使用openpyxl查找单元时遇到问题

我试图find一个单元格在Excel中的值,首先find它所在的行,然后通过单元格的坐标(列将每次相同)。

我尝试使用下面的代码,与它的问题是,它rownum不是行数(正如我所期待的)。 请有人可以帮我find包含我正在寻找的值的行号:

wb = openpyxl.load_workbook('C:\\rtemp\\Names.xlsx') ws = wb['Sheet5'] rownum = 0 for row in ws: for cell in row: if cell.value == 'ResellBalance': rownum = row break ExcelValue = ws.cell(row=rownum, column=2).value print(ExcelValue) 

我无法find一个函数来查找行号,但是我可以通过使用以下命令find具有所查找的单元格的行号:

 wb = openpyxl.load_workbook('C:\\rtemp\\Names.xlsx') ws = wb['Sheet5'] rownum = 0 for row in ws: for cell in row: if cell.value == 'ResellBalance': rownum = rownum + 1 break FieldName = (ws.cell(row=rownum, column=2).value)