excel数据比对小工具

class excel_compare(QWidget): def __init__(self): QWidget.__init__(self) self.compare_ui = excel多功能比对界面.Ui_Form() self.compare_ui.setupUi(self) def excel_true_false(): if window.compare_ui.lineEdit.text() and window.compare_ui.lineEdit_2.text() and window.compare_ui.lineEdit_3.text() and window.compare_ui.lineEdit_4.text() and window.compare_ui.lineEdit_5.text() and window.compare_ui.lineEdit_6.text() and window.compare_ui.lineEdit_7.text(): file_path_original = r'' str(window.compare_ui.lineEdit.text())#转义文件路径,怕有奇葩名字 data_original = xlrd.open_workbook(file_path_original) #获取sheet table_original = data_original.sheet_by_name(str(window.compare_ui.lineEdit_3.text())) #获取总行数 nrows_original = table_original.nrows #获取总列数 ncols_original = table_original.ncols li_original = [] for i in range(1,nrows_original): # print("333") cell_value = table_original.cell(i,int(window.compare_ui.lineEdit_4.text()) - 1).value li_original.append(cell_value) # print(li_original) file_path_target = r'' str(window.compare_ui.lineEdit_2.text()) data_target = xlrd.open_workbook(file_path_target) # 获取sheet table_target = data_target.sheet_by_name(window.compare_ui.lineEdit_5.text()) # 获取总行数 nrows_target = table_target.nrows # 获取总列数 ncols_target = table_target.ncols # global li_target li_target = [] for u in range(1, nrows_target): cell_value = table_target.cell(u, int(window.compare_ui.lineEdit_6.text()) - 1).value li_target.append(cell_value) # print(li_target) # print(li_target) # file_path_original = r'E:\python项目\EXCEL对比\test.xls' # w_sheet = wbook.get_sheet(0) # 索引sheet表 # print("123") original_file = pd.ExcelFile(file_path_original) original_sheetnames = original_file.sheet_names # print(original_sheetnames) for original_sheetnames_index in range(0,len(original_sheetnames)): if window.compare_ui.lineEdit_3.text() == original_sheetnames[original_sheetnames_index]: original_sheetnames_INDEX = original_sheetnames_index rbook = xlrd.open_workbook(file_path_original) # 打开文件 wbook = copy.copy(rbook) # 复制文件并保留格式 w_sheet = wbook.get_sheet(original_sheetnames_INDEX) # 索引sheet表 a = int(window.compare_ui.lineEdit_7.text()) - 1 for index in range(0,len(li_original)): if li_original[index] in li_target: w_sheet.write(index 1,a, "true") else: w_sheet.write(index 1,a, "false") wbook.save(file_path_original) # 保存文件 root = tk.Tk() root.withdraw() msgbox.showerror(title="提示", message="比对完成") else: root = tk.Tk() root.withdraw() msgbox.showerror(title="警告", message="有数据没有输入或数据输入错误!")