As business needs, VBA may not be suitable for my colleagues are not familiar with the use of code
Thus VBA code into the original packaging and Python code, performing a subsequent opportunity to improve
The complete code
Import to xlrd Import xlwt from xlutils.copy Import Copy from Tkinter Import * DEF runl (): QT1, Qt2 = 0,0 # open form the try : Workbook = xlrd.open_workbook (R & lt ' . fendan.xlsx \\ ' ) the except : TXT .insert (END, ' open table fails, check to see if a table has been created fendan.xlsx ' ) txt.insert (END, ' \ the n- ' ) # get the name sheet_names = workbook.sheet_names() #获取对象 sheet1 = workbook.sheet_by_name('Sheet1') ##wb = xlwt.Workbook(r'.\\fendan.xlsx') ##ws = wb.get_sheet(0) write_data = copy(workbook) write_save = write_data.get_sheet(0) nrows = sheet1.nrows #前处理,将订单号取消尾数 for i in range(1,nrows): if not sheet1.cell_value(rowx=i,colx=1)[:10] =='': ## print(sheet1.cell_value(rowx=i,colx=1)[:10]) #Take two i-th row before writing the number i row 10 3 write_save.write (i, 2, sheet1.cell_value (i = rowx, COLX =. 1) [: 10 ]) write_data.save ( ' fendan2.xlsx ' ) # open table Workbook2 = xlrd.open_workbook (R & lt ' . fendan2.xlsx \\ ' ) # get the object Sheet2 = workbook2.sheet_by_name ( ' Sheet1 ' ) write_data2 = Copy (Workbook2) write_save2 = write_data2.get_sheet (0) # set write into the pattern. 1 font0 = xlwt.Font () the pattern1 = xlwt.Pattern () pattern1.pattern = xlwt.Pattern.SOLID_PATTERN pattern1.pattern_fore_colour = 5 style0 = xlwt.XFStyle() style0.pattern = pattern1 #设置写入样式2 pattern2 = xlwt.Pattern() pattern2.pattern = xlwt.Pattern.SOLID_PATTERN pattern2.pattern_fore_colour = 5 pattern2.pattern_fore_colour = 2 style1 = xlwt.XFStyle() style1.pattern = pattern2 nrows = sheet2.nrows for k in range(1,nrows): for r in range(1,nrows): if not sheet2.cell_value(rowx=k,colx=2) == '': ## print(k,r) if sheet2.cell_value(rowx=r,colx=2) == sheet2.cell_value(rowx=k,colx=5): ## print(sheet2.cell_value(rowx=r,colx=2),sheet2.cell_value(rowx=k,colx=5)) ## print(sheet2.cell_value(rowx=r,colx=2) == sheet2.cell_value(rowx=k,colx=5)) if sheet2.cell_value(rowx=r,colx=3) == sheet2.cell_value(rowx=k,colx=6): ## print(sheet2.cell_value(rowx=r,colx=3),sheet2.cell_value(rowx=k,colx=6)) ## print(sheet2.cell_value(rowx=r,colx=3) == sheet2.cell_value(rowx=k,colx=6)) write_save2.write(r,2,sheet2.cell_value(rowx=r,colx=2),style=style0) write_save2.write(r,3,sheet2.cell_value(rowx=r,colx=3),style=style0) write_save2.write(k,5,sheet2.cell_value(rowx=k,colx=5),style=style1) write_save2.write(k,6,sheet2.cell_value(rowx=k,colx=6),style=style1) qt1 = qt1 +sheet2.cell_value(rowx=r,colx=3) qt2 = qt2 +sheet2.cell_value(rowx=k,colx=6) ## print(sheet1.row_values(rowx=r,start_colx=2,end_colx=7)) write_data2.save('fendan2.xlsx') ## print(qt1,qt2) txt.insert(END, '区分完毕') txt.insert(END, '\n') txt.insert(END, (qt1,qt2)) txt.insert(END, '\n') root = Tk() root.title('区分订单') root.geometry('460x300 ' ) Lb1 = the Label (root, text = ' Please enter a third, four, six, seven, respectively, the number of orders in an Excel spreadsheet ' ) lb1.place (relx = 0.1, RELY = 0.1, relwidth = 0.8, relheight 0.1 = ) btn1 = the button (the root, text = ' enter End Close Excel spreadsheet, clicking the button ' , Command = runl) btn1.place (relx = 0.2, RELY = 0.2, relwidth = 0.6, relheight = 0.3 ) TXT = the text (the root) txt.place (RELY = 0.6, relheight = 0.3 ) Lb2 = the Label (the root, text = ' OF: of YBX ' ) lb2.place (relx = 0.8, RELY = 0.9, relwidth = 0.2, 0.1 = relheight) Root.mainloop ()
He expressed gratitude to the following references: