对比两个excel文件,不同内容写入txt文件
def find_difference_bwteen_two_xls(excel1,excel2): excel1 = xlrd.open_workbook(excel1) excel2 = xlrd.open_workbook(excel2) excel1_sheet1 = excel1.sheet_by_index(0) excel2_sheet1 = excel2.sheet_by_index(0) rows = excel1_sheet1.nrows cols = excel1_sheet1.ncols with open("resulst.txt","a") as f: # 遍历excel文件 for i in range(rows): for j in range(cols): v1 = excel1_sheet1.cell_value(i,j) v2 = excel2_sheet1.cell_value(i,j) if v1 != v2: f.write('第%d行%d列单元内容不同:excel1中为%s,excel2中为%s\n'%(i+1,j+1,v1,v2)) find_difference_bwteen_two_xls('testdata1.xls','testdata2.xls')