比较两个Excel文件并使用Python打印差异?
我有2个XLSX文件,需要打印文件中每个单元格中的差异。我现在使用的代码正在工作,但我需要忽略每个XLSX文件中的第一列,我不确定如何将该异常添加到我当前使用的代码中。
ds1 = xlrd.open_workbook("PATH1")
ds2 = xlrd.open_workbook("PATH2")
SHEET1 = ds1.sheet_by_index(0)
SHEET1 = ds2.sheet_by_index(0)
for rownum in range(max(POB_ds1.nrows, POB_ds2.nrows)):
if rownum < SHEET1_ds1.nrows:
row_rb1 = SHEET1_ds1.row_values(rownum)
row_rb2 = SHEET1_ds2.row_values(rownum)
for colnum, (c1, c2) in enumerate(zip_longest(row_rb1, row_rb2)):
if c1 != c2:
print ("Row {} Col {} - {} != {}".format(rownum+1, colnum+1, c1, c2))
else:
print ("Row {} missing".format(rownum+1))
I have 2 xlsx files and need to print the differences in each cell in the file. The code that I am using now is working but I need to ignore the first column in each of the xlsx files and I am not sure how to add that exception to the code I am currently using.
ds1 = xlrd.open_workbook("PATH1")
ds2 = xlrd.open_workbook("PATH2")
SHEET1 = ds1.sheet_by_index(0)
SHEET1 = ds2.sheet_by_index(0)
for rownum in range(max(POB_ds1.nrows, POB_ds2.nrows)):
if rownum < SHEET1_ds1.nrows:
row_rb1 = SHEET1_ds1.row_values(rownum)
row_rb2 = SHEET1_ds2.row_values(rownum)
for colnum, (c1, c2) in enumerate(zip_longest(row_rb1, row_rb2)):
if c1 != c2:
print ("Row {} Col {} - {} != {}".format(rownum+1, colnum+1, c1, c2))
else:
print ("Row {} missing".format(rownum+1))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种方法怎么样?
有关所有详细信息,请参见下面的链接。
https://pbpython.com/excel-diff-pandas.htas.html
How about this approach?
See the link below for all details.
https://pbpython.com/excel-diff-pandas.html