我试图用Python中的Ppenpyxl比较不同工作簿中的2个Excel列。到目前为止,我得到的是:
#Load the workbooks
wkb1 = load_workbook(filename = os.path.join(srcdir, "wbk1.xlsx"))
wkb2 = load_workbook(filename = os.path.join(srcdir, "wbk2.xlsx"))
#Find the last row of the excel data
ws1 = wkb1.active
wkb1_LastRow = ws1.max_row
ws2 = wkb2.active
wkb2_LastRow = ws2.max_row
for xrow in range (1,(wkb1_LastRow+1)):
for yrow in range (1,(wkb2_LastRow+1)):
print (ws1.cell(row=xrow, column=1).value, ws2.cell(row=yrow, column=1).value )
if ws1.cell(row=xrow, column=1).value == ws2.cell(row=yrow, column=1).value:
print('HIT')
问题是if语句总是失败,即使这两列包含相同的值:
^{pr2}$有什么想法吗?在
使用嵌套循环的FWIW不是这样做的方法。使用
zip
要简单得多。在以下措施应该有效:
相关问题 更多 >
编程相关推荐