import pandas as pd
import tkinter as tk
#import numpy as np #设置 numpy.ndarray类型 数据的打印长度
import json #打印双引号
import tkinter.font as tf #text 多行文本框里面字体的颜色
from tkinter import messagebox #弹窗
from tkinter import ttk
from tkinter.filedialog import askdirectory #选择导出路径
from tkinter import *
import copy # 列表深拷贝
# from log_api import LoggerHandler
#pyinstaller -F -w -i ico.ico merge.py
class mergetool:
def __init__(self):
###############################################################################################################
#self.logger_info_converting_main = LoggerHandler("info_main", file="info_main")
###############################################################################################################
windows = tk.Tk()
# 设置窗口大小
winWidth = 860
winHeight = 600
# 获取屏幕分辨率
screenWidth = windows.winfo_screenwidth()
screenHeight = windows.winfo_screenheight()
print(winWidth)
print(winHeight)
print(screenWidth)
print(screenHeight)
x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)
windows.title("uMac巡检模板差异比较工具1.0")
windows.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y)) ## 规定窗口大小800*600像素
#windows.geometry(f'{winWidth}x{winHeight}')
windows.resizable(False, False) ## 规定窗口不可缩放
#windows["bg"] = "pink" # 窗口背景色,其他背景色见
#windows.attributes("-alpha", 0.8) # 虚化 值越小虚化程度越高
self.frm_root = tk.Frame(windows)
self.frm_head = tk.Frame(self.frm_root, height=20, width=winWidth-20)
self.frm_infoShow = tk.Frame(self.frm_root, height=winHeight-20, width=winWidth-20)
self.frm_head.pack_propagate(0)
self.frm_infoShow.pack_propagate(0)
self.frm_root.pack()
self.frm_head.pack()
self.frm_infoShow.pack()
self.lab1 = tk.Label(self.frm_head, text="模板A", height=1, width=6, fg='black', font=('微软雅黑', 10))
self.lab1.grid(row=0, column=0, padx=1, pady=5)
self.lab2 = tk.Label(self.frm_head, text="模板B", height=1, width=6, fg='black', font=('微软雅黑', 10))
self.lab2.grid(row=0, column=3, padx=1, pady=5)
self.showTextA = tk.StringVar() # 框上面的值
self.textA_var = tk.Entry(self.frm_head, textvariable=self.showTextA, width=28) # 框上面的值 赋值给 本地变量
self.textA_var.grid(row=0, column=1, padx=1, pady=5)
self.showTextB = tk.StringVar()
self.textB_var = tk.Entry(self.frm_head, textvariable=self.showTextB, width=28)
self.textB_var.grid(row=0, column=4, padx=1, pady=5)
self.selectAButton = tk.Button(self.frm_head, text='选取', command=self.selectFileA, fg="black", font=('微软雅黑', 10), relief=GROOVE)
self.selectAButton.grid(row=0, column=2, padx=1, pady=5)
self.selectBButton = tk.Button(self.frm_head, text='选取', command=self.selectFileB, fg="black", font=('微软雅黑', 10), relief=GROOVE)
self.selectBButton.grid(row=0, column=5, padx=1, pady=5)
self.mergeButton = tk.Button(self.frm_head, text='执行比对', command=self.mergeData, bg="lightblue", font=('微软雅黑', 10))
self.mergeButton.grid(row=0, column=6, padx=10, pady=5)
##############################################################################################################
# 结果info 用 entry 不行,要用 text
#self.showResultInfo = tk.StringVar()
#self.info_text_var = tk.Entry(self.frm_infoShow, textvariable=self.showResultInfo, width=winWidth-100)
#self.info_text_var.grid(row=1, column=0, rowspan=5, columnspan=10)
s1 = tk.Scrollbar(self.frm_infoShow, orient=tk.HORIZONTAL)#水平滚动条
s2 = tk.Scrollbar(self.frm_infoShow, orient=tk.VERTICAL)#竖直滚动条
#self.textResult = tk.Text(self.frm_infoShow, width=115, height=42, xscrollcommand=s1.set, yscrollcommand=s2.set, wrap=tk.NONE, highlightthickness=1, highlightcolor='red', highlightbackground='yellow')
self.textResult = tk.Text(self.frm_infoShow, width=115, height=42, xscrollcommand=s1.set, yscrollcommand=s2.set, wrap=tk.NONE, highlightthickness=1, highlightcolor='red', highlightbackground='yellow')
s1.pack(side=tk.BOTTOM, fill=tk.X)
s1.config(command=self.textResult.xview)
s2.pack(side=tk.RIGHT, fill=tk.Y)
s2.config(command=self.textResult.yview)
#self.text.grid(row=1, column=0)
self.textResult.pack()
#https://www.cnblogs.com/chenyuebai/p/7150382.html
self.textResult.tag_configure("tag_red", foreground="red")
self.textResult.tag_configure("tag_blue", foreground="blue")
'''
ft = tf.Font(family='微软雅黑', size=10) ###有很多参数
self.textResult.tag_add('tag_1',) # 申明一个tag,在a位置使用
self.textResult.tag_config('tag_1', foreground='red', font=ft) # 设置tag即插入文字的大小,颜色等
self.textResult.tag_add('tag_2')
self.textResult.tag_config('tag_2', foreground='blue', font=ft)
'''
self.textColor = ['tag_red', 'tag_blue']
self.selectColor = self.textColor[0]
##############################################################################################################
self.fileAPath = tk.StringVar()
self.fileBPath = tk.StringVar()
windows.mainloop()
def alternateSetColor(self):
if self.selectColor == self.textColor[0]:
self.selectColor = self.textColor[1]
else:
self.selectColor = self.textColor[0]
def getFileAPPath(self):
self.fileAPath.set('')
self.fileAPath.set(filedialog.askopenfilename(title='选择待导入的Excel文件A', filetypes=[('Excel', '*.xlsx'), ('All Files', '*')]))
def getFileBPPath(self):
self.fileBPath.set('')
self.fileBPath.set(filedialog.askopenfilename(title='选择待导入的Excel文件B', filetypes=[('Excel', '*.xlsx'), ('All Files', '*')]))
def selectFileA(self):
self.getFileAPPath()
self.showTextA.set('')
self.textA_var.insert('end', self.fileAPath.get())
def selectFileB(self):
self.getFileBPPath()
self.showTextB.set('')
self.textB_var.insert('end', self.fileBPath.get())
def insertResultToTextWindows(self, conment):
self.textResult.insert('end', conment, self.selectColor)
self.textResult.insert(tk.INSERT, '\n')
#超链接里的,缩进显示
def insertResultToTextWindowsSecondLayer(self, conment):
self.textResult.insert('end', ' ')
self.textResult.insert('end', conment, self.selectColor)
self.textResult.insert(tk.INSERT, '\n')
def deleteAllTextInWindows(self):
self.textResult.delete(0.0, tk.END)
def readExelAndCompare(self, fileAPath, fileBPath):
print("----------------------------------readExelAndCompare start")
#pd.set_option('display.max_columns', None)
#显示所有行
#pd.set_option('display.max_rows', None)
try:
self.excelDataA = pd.read_excel(str(fileAPath), sheet_name=None, dtype = str, keep_default_na=False) #指定读取第一张表,0位置 ; 第0列转换为字符型 ; keep_default_na 后面加上keep_default_na=False,这样读取到空字符串时读出的就是''而不是nan了
self.excelDataB = pd.read_excel(str(fileBPath), sheet_name=None, dtype = str, keep_default_na=False) #指定读取第一张表,0位置 ; 第0列转换为字符型 ; keep_default_na 后面加上keep_default_na=False,这样读取到空字符串时读出的就是''而不是nan了
except Exception as err:
tk.messagebox.showerror('excel打开失败', 'ERROR :%s' % (err))
return
#np.set_printoptions(threshold=10000)
print('fileAPath : %s' % fileAPath)
print(self.excelDataA)
print("--------------------------")
print('fileBPath : %s' % fileBPath)
print(self.excelDataB)
print("--------------------------")
workbook_A_list = []
workbook_B_list = []
workbook_A_list_temp = []
workbook_B_list_temp = []
for sheet_name in self.excelDataA:
try:
float(sheet_name)
except ValueError:
# sheetname 非纯数字 - 测试条目
workbook_A_list.append(sheet_name)
for sheet_name in self.excelDataB:
try:
float(sheet_name)
except ValueError:
# sheetname 非纯数字 - 测试条目
workbook_B_list.append(sheet_name)
print(workbook_A_list)
print(workbook_B_list)
workbook_A_list_temp = copy.deepcopy(workbook_A_list)
workbook_B_list_temp = copy.deepcopy(workbook_B_list)
print("--------------------------")
rowDataA = {}
self.rowDataA_Ext = {}
configDataMap = {}
for sheet_name_A in workbook_A_list:
for sheet_name_B in workbook_B_list:
self.differentNum = 0
print("sheet_name_A:%s, sheet_name_B:%s" % (sheet_name_A, sheet_name_B))
if sheet_name_A == sheet_name_B and sheet_name_A != "配置巡检项" and sheet_name_A != '' and sheet_name_A != 'cm_patrol_item':
workbook_A_list_temp.remove(sheet_name_A) #比较完,剔除掉
workbook_B_list_temp.remove(sheet_name_A) #比较完,剔除掉
rowDataA.clear() # one sheet compare start, clear dictionary
configDataMap.clear() # one sheet compare start, clear dictionary
self.rowDataA_Ext.clear() # one sheet compare start, clear dictionary
self.alternateSetColor()
print("**** Compare workbook(%s) start" % sheet_name_A)
self.insertResultToTextWindows("**** Compare workbook(%s) start" % sheet_name_A)
rowNum_A = self.excelDataA[sheet_name_A].shape[0]
columnNum_A = self.excelDataA[sheet_name_A].shape[1]
print("--------------------------")
print("sheet_name_A:%s, rowNum:%d, columnNum:%d" % (sheet_name_A, rowNum_A, columnNum_A))
print("-----------")
print(self.excelDataA.get(sheet_name_A))
print("-----------")
rowNum_B = self.excelDataB[sheet_name_B].shape[0]
columnNum_B = self.excelDataB[sheet_name_B].shape[1]
print("--------------------------")
print("sheet_name_B:%s, rowNum:%d, columnNum:%d" % (sheet_name_B, rowNum_B, columnNum_B))
print("-----------")
print(self.excelDataB.get(sheet_name_B))
print("-----------")
if (rowNum_A == 0 and columnNum_A == 0 and rowNum_B == 0 and columnNum_B == 0):
rowDataA.clear() # one sheet compare over, clear dictionary
print("两个表格的sheet,均为空,没有比较的意义!!!")
continue
if ((rowNum_A == 0 or columnNum_A == 0) and (rowNum_B != 0 and columnNum_B != 0)):
print("sheet_A为空,sheet_B非空!!!")
rowDataA.clear()
continue
if ((rowNum_A != 0 and columnNum_A != 0) and (rowNum_B == 0 or columnNum_B == 0)):
print("sheet_B为空,sheet_A非空!!!")
rowDataA.clear()
continue
for i in range(rowNum_A): # 行
if columnNum_A > 0:
dicIndex = self.excelDataA[sheet_name_A].loc[i].values[0]
if dicIndex != None and dicIndex != '':
rowDataA[dicIndex] = self.excelDataA[sheet_name_A].loc[i].values
print('===========================A')
print(rowDataA)
print('===========================A')
for i in range(rowNum_B): # 行
if columnNum_B > 0:
try:
dicIndex = self.excelDataB[sheet_name_B].loc[i].values[0]
if dicIndex != None and dicIndex != '':
print('==B')
print(dicIndex)
print(type(rowDataA[dicIndex]))
print(type(self.excelDataB[sheet_name_B].loc[i].values))
print('==B')
if rowDataA[dicIndex].tolist() == self.excelDataB[sheet_name_B].loc[i].values.tolist():
print("比较成功!!!")
print("-----------A")
print(rowDataA[dicIndex].tolist())
print("-----------B")
print(self.excelDataB[sheet_name_B].loc[i].values.tolist())
print("-----------END")
del rowDataA[dicIndex] # 比较完毕,删除之
else:
print("比较失败!!!")
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(rowDataA[dicIndex].tolist())
self.insertResultToTextWindows(json.dumps(rowDataA[dicIndex].tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(self.excelDataB[sheet_name_B].loc[i].values.tolist())
self.insertResultToTextWindows(json.dumps(self.excelDataB[sheet_name_B].loc[i].values.tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------C")
del rowDataA[dicIndex] # 比较完毕,删除之
self.insertResultToTextWindows("-------------")
self.differentNum += 1
except Exception as err:
print('比较失败,A不存在,B存在的,上报结果', 'ERROR :%s' % (err))
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(" ")
self.insertResultToTextWindows(" ")
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(self.excelDataB[sheet_name_B].loc[i].values.tolist())
self.insertResultToTextWindows(json.dumps(self.excelDataB[sheet_name_B].loc[i].values.tolist(),ensure_ascii=False))
print("-----------C")
self.insertResultToTextWindows("-------------")
self.differentNum += 1
if len(rowDataA) != 0:
for key in rowDataA:
print('比较失败,B不存在,A存在的,上报结果, ERROR ')
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(rowDataA[key].tolist())
self.insertResultToTextWindows(json.dumps(rowDataA[key].tolist(),ensure_ascii=False))
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(" ")
self.insertResultToTextWindows(" ")
print("-----------C")
self.insertResultToTextWindows("-------------")
#self.alternateSetColor()
self.differentNum += 1
self.insertResultToTextWindows("**** Compare workbook(%s) finish, different data num : %d " % (sheet_name_A, self.differentNum))
self.insertResultToTextWindows(" ")
elif (sheet_name_A == 'cm_patrol_item' or sheet_name_A == "配置巡检项") and sheet_name_A == sheet_name_B:########开始比较 配置巡检项
workbook_A_list_temp.remove(sheet_name_A) #比较完,剔除掉
workbook_B_list_temp.remove(sheet_name_A) #比较完,剔除掉
rowDataA.clear() # one sheet compare start, clear dictionary
configDataMap.clear() # one sheet compare start, clear dictionary
self.rowDataA_Ext.clear() # one sheet compare start, clear dictionary
self.alternateSetColor()
print("**** Compare workbook(%s) start" % sheet_name_A)
self.insertResultToTextWindows("**** Compare workbook(%s) start" % sheet_name_A)
rowNum_A = self.excelDataA[sheet_name_A].shape[0]
columnNum_A = self.excelDataA[sheet_name_A].shape[1]
print("--------------------------")
print("sheet_name_A:%s, rowNum:%d, columnNum:%d" % (sheet_name_A, rowNum_A, columnNum_A))
print("-----------")
print(self.excelDataA.get(sheet_name_A))
print("-----------")
rowNum_B = self.excelDataB[sheet_name_B].shape[0]
columnNum_B = self.excelDataB[sheet_name_B].shape[1]
print("--------------------------")
print("sheet_name_B:%s, rowNum:%d, columnNum:%d" % (sheet_name_B, rowNum_B, columnNum_B))
print("-----------")
print(self.excelDataB.get(sheet_name_B))
print("-----------")
if (rowNum_A == 0 and columnNum_A == 0 and rowNum_B == 0 and columnNum_B == 0):
rowDataA.clear() # one sheet compare over, clear dictionary
print("两个表格的sheet,均为空,没有比较的意义!!!")
continue
if ((rowNum_A == 0 or columnNum_A == 0) and (rowNum_B != 0 and columnNum_B != 0)):
print("sheet_A为空,sheet_B非空!!!")
rowDataA.clear()
continue
if ((rowNum_A != 0 and columnNum_A != 0) and (rowNum_B == 0 or columnNum_B == 0)):
print("sheet_B为空,sheet_A非空!!!")
rowDataA.clear()
continue
for i in range(rowNum_A): # 行
dicKey_1 = self.excelDataA[sheet_name_A].loc[i].values[1]
if columnNum_A > 1 and dicKey_1 != '' and dicKey_1 != None:
dicKey_0 = self.excelDataA[sheet_name_A].loc[i].values[0]
try:
float(dicKey_0)
if dicKey_0 != None and dicKey_0 != '':
rowDataA[dicKey_1] = self.excelDataA[sheet_name_A].loc[i].values[1:-1]
configDataMap[dicKey_1] = dicKey_0
except Exception as err:
print('配置巡检项 不满足首列为数字,第二列为key的特性', 'ERROR INFO :%s' % (err))
print('===========================EE')
print(rowDataA)
print(configDataMap)
print('===========================EE')
for i in range(rowNum_B): # 行
if columnNum_B > 0:
try:
dicIndex = self.excelDataB[sheet_name_B].loc[i].values[1]
dicIndex_B_Ext = self.excelDataB[sheet_name_B].loc[i].values[0]
if dicIndex != None and dicIndex != '':
print('==D')
print(dicIndex)
print(type(rowDataA[dicIndex]))
print(type(self.excelDataB[sheet_name_B].loc[i].values[1:-1]))
print('==D')
if rowDataA[dicIndex].tolist() == self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist():
print("比较成功!!!")
print("-----------A")
print(rowDataA[dicIndex].tolist())
print("-----------B")
print(self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist())
print("-----------END")
#self.insertResultToTextWindows("-------------A:(%s, %s) B:(%s, %s) " % (dicIndex,configDataMap[dicIndex], dicIndex,dicIndex_B_Ext))
self.compareLevelTwoDirectory(dicIndex, configDataMap[dicIndex], dicIndex_B_Ext, self.excelDataB[sheet_name_B].loc[i].values[4])
#self.insertResultToTextWindows("-------------")
del rowDataA[dicIndex] # 比较完毕,删除之
else:
print("比较失败!!!")
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(rowDataA[dicIndex].tolist())
self.insertResultToTextWindows(json.dumps(rowDataA[dicIndex].tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist())
self.insertResultToTextWindows(json.dumps(self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------C")
del rowDataA[dicIndex] # 比较完毕,删除之
self.insertResultToTextWindows("-------------")
self.differentNum += 1
except Exception as err:
print('比较失败,A不存在,B存在的,上报结果', 'ERROR :%s' % (err))
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(" ")
self.insertResultToTextWindows(" ")
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist())
self.insertResultToTextWindows(json.dumps(self.excelDataB[sheet_name_B].loc[i].values[1:-1].tolist(),ensure_ascii=False))
print("-----------C")
self.insertResultToTextWindows("-------------")
self.differentNum += 1
if len(rowDataA) != 0:
for key in rowDataA:
print('比较失败,B不存在,A存在的,上报结果, ERROR ')
print("-----------A")
self.insertResultToTextWindows("-------------A:")
print(rowDataA[key].tolist())
self.insertResultToTextWindows(json.dumps(rowDataA[key].tolist(),ensure_ascii=False))
print("-----------B")
self.insertResultToTextWindows("-------------B:")
print(" ")
self.insertResultToTextWindows(" ")
print("-----------C")
self.insertResultToTextWindows("-------------")
#self.alternateSetColor()
self.differentNum += 1
self.insertResultToTextWindows("**** Compare workbook(%s) finish, different data num : %d " % (sheet_name_A, self.differentNum))
self.insertResultToTextWindows(" ")
print("----------------------------------readExelAndCompare end")
def compareLevelTwoDirectory(self, itemKey, indexA, indexB, Method):
print("compareLevelTwoDirectory: indexA:%s, indexB:%s" % (indexA, indexB))
rowNum_A = self.excelDataA[indexA].shape[0]
columnNum_A = self.excelDataA[indexA].shape[1]
print("sheet_name_A_A rowNum:%d, columnNum:%d" % (rowNum_A, columnNum_A))
rowNum_B = self.excelDataB[indexB].shape[0]
columnNum_B = self.excelDataB[indexB].shape[1]
print("sheet_name_B_B rowNum:%d, columnNum:%d" % (rowNum_B, columnNum_B))
self.rowDataA_Ext.clear() # one sheet compare start, clear dictionary
print("-----------A")
print(self.excelDataA.get(indexA))
print("-----------B")
print(self.excelDataB.get(indexB))
print("-----------END--")
if (rowNum_A == 0 and columnNum_A == 0 and rowNum_B == 0 and columnNum_B == 0):
rowDataA.clear() # one sheet compare over, clear dictionary
print("两个表格的sheet,均为空,没有比较的意义!!!")
return
if ((rowNum_A == 0 or columnNum_A == 0) and (rowNum_B != 0 and columnNum_B != 0)):
print("sheet_A为空,sheet_B非空!!!")
rowDataA.clear()
return
if ((rowNum_A != 0 and columnNum_A != 0) and (rowNum_B == 0 or columnNum_B == 0)):
print("sheet_B为空,sheet_A非空!!!")
rowDataA.clear()
return
for i in range(rowNum_A): # 行
if columnNum_A > 0:
dicIndex = self.excelDataA[indexA].loc[i].values[0]
if dicIndex != None and dicIndex != '':
self.rowDataA_Ext[dicIndex] = self.excelDataA[indexA].loc[i].values
print('===========================Ext A')
print(self.rowDataA_Ext)
print('===========================Ext A')
ifHasReport = False
for i in range(rowNum_B): # 行
if columnNum_B > 0:
try:
dicIndex = self.excelDataB[indexB].loc[i].values[0]
if dicIndex != None and dicIndex != '':
print('==EXT AB')
print(dicIndex)
print(self.rowDataA_Ext[dicIndex])
print('==EXT AB')
if self.rowDataA_Ext[dicIndex].tolist() == self.excelDataB[indexB].loc[i].values.tolist():
print("比较成功!!!")
print("-----------A")
print(self.rowDataA_Ext[dicIndex].tolist())
print("-----------B")
print(self.excelDataB[indexB].loc[i].values.tolist())
print("-----------END")
#self.compareLevelTwoDirectory()
del self.rowDataA_Ext[dicIndex] # 比较完毕,删除之
else:
print("比较失败!!!")
print("-----------A")
if ifHasReport == False:
self.insertResultToTextWindows("-------------itemKey:%s indexA:%s indexB:%s" % (itemKey, indexA, indexB))
ifHasReport = True
self.insertResultToTextWindowsSecondLayer("----A:")
print(self.rowDataA_Ext[dicIndex].tolist())
self.insertResultToTextWindowsSecondLayer(json.dumps(self.rowDataA_Ext[dicIndex].tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------B")
self.insertResultToTextWindowsSecondLayer("-B:")
print(self.excelDataB[indexB].loc[i].values.tolist())
self.insertResultToTextWindowsSecondLayer(json.dumps(self.excelDataB[indexB].loc[i].values.tolist(),ensure_ascii=False))#为了支持中文 ensure_ascii=False
print("-----------C")
self.insertResultToTextWindowsSecondLayer("--")
del self.rowDataA_Ext[dicIndex] # 比较完毕,删除之
self.differentNum += 1
except Exception as err:
print('比较失败,A不存在,B存在的,上报结果', 'ERROR :%s' % (err))
print("-----------A")
if ifHasReport == False:
self.insertResultToTextWindows("-------------itemKey:%s indexA:%s indexB:%s" % (itemKey, indexA, indexB))
ifHasReport = True
self.insertResultToTextWindowsSecondLayer("-A:")
print(" ")
self.insertResultToTextWindowsSecondLayer(" ")
print("-----------B")
self.insertResultToTextWindowsSecondLayer("-B:")
print(self.excelDataB[indexB].loc[i].values.tolist())
self.insertResultToTextWindowsSecondLayer(json.dumps(self.excelDataB[indexB].loc[i].values.tolist(),ensure_ascii=False))
print("-----------C")
self.insertResultToTextWindowsSecondLayer("--")
self.differentNum += 1
if len(self.rowDataA_Ext) != 0:
for key in self.rowDataA_Ext:
print('比较失败,B不存在,A存在的,上报结果, ERROR ')
print("-----------A")
if ifHasReport == False:
self.insertResultToTextWindows("-------------itemKey:%s indexA:%s indexB:%s" % (itemKey, indexA, indexB))
ifHasReport = True
self.insertResultToTextWindowsSecondLayer("-A:")
print(self.rowDataA_Ext[key].tolist())
self.insertResultToTextWindowsSecondLayer(json.dumps(self.rowDataA_Ext[key].tolist(),ensure_ascii=False))
print("-----------B")
self.insertResultToTextWindowsSecondLayer("-B:")
print(" ")
self.insertResultToTextWindowsSecondLayer(" ")
print("-----------C")
self.insertResultToTextWindowsSecondLayer("--")
#self.alternateSetColor()
self.differentNum += 1
def mergeData(self):
if self.fileAPath.get() == '' or self.fileBPath.get() == '':
tk.messagebox.showwarning('警告', '请选择2个不同的模板进行比较!\n\n模板A : %s\n模板B : %s\n' % (self.fileAPath.get(), self.fileBPath.get()))
return
elif self.fileAPath.get() == self.fileBPath.get():
tk.messagebox.showwarning('警告', '模板A、B路径相同,请选择2个不同的模板进行比较!\n\n模板A : %s\n模板B : %s\n' % (self.fileAPath.get(), self.fileBPath.get()))
return
self.deleteAllTextInWindows()
self.readExelAndCompare(self.fileAPath.get(), self.fileBPath.get())
# rowNum = self.excelDataA.shape[0]
# columnNum = self.excelDataA.shape[1]
print("button")
pass
mergetool()
python - excel merger工具
最新推荐文章于 2024-08-21 14:05:40 发布
该代码实现了一个基于Tkinter的Python GUI工具,用于比较两个Excel模板的差异。用户可以选择要比较的文件,工具将显示不同数据的详细对比,并提供结果的文本输出。主要功能包括文件选择、数据读取、差异显示以及颜色交替显示差异。
摘要由CSDN通过智能技术生成