无法将用户输入与 openpyxl 中的单元格值进行比较
Can't compare user input to cell value in openpyxl
I am trying to ask user input and compare the input to a column in my excel sheet. But I keep getting null and I can't get the compare value.
wb = xl.load_workbook(filename + ".xlsx")
sheet1 = wb.active
wb2 = xl.load_workbook("database.xlsx")
sheet2 = wb2.active
pn = input("Please enter PN: ")
col_B = sheet2['B']
for cell in col_B:
if cell.value == pn:
print(cell)
else:
print("null")
break
删除“中断”。否则它将在读取第一个单元格后停止循环。
I am trying to ask user input and compare the input to a column in my excel sheet. But I keep getting null and I can't get the compare value.
wb = xl.load_workbook(filename + ".xlsx")
sheet1 = wb.active
wb2 = xl.load_workbook("database.xlsx")
sheet2 = wb2.active
pn = input("Please enter PN: ")
col_B = sheet2['B']
for cell in col_B:
if cell.value == pn:
print(cell)
else:
print("null")
break
删除“中断”。否则它将在读取第一个单元格后停止循环。