解决问题:
在读取excel时, 假如读取到了我想要的数据,则返回它所在的行和列
import openpyxl # 打开Excel文件并选择工作表 wb = openpyxl.load_workbook(r'D:\Users\72036454\Desktop\test.xlsx') sheet = wb['Sheet1'] # 遍历整个工作表,查找特定值 target_value = 'hello' # 假设要查找的值为 hello for row in sheet.iter_rows(): # 遍历所有行 for cell in row: if cell.value == target_value: # 如果找到了目标值 row_number = cell.row # 记录所在行数 column_number = cell.column # 记录所在列数 print(f'所在行:{row_number}') print(f'所在列:{column_number}') break # 退出查找
标签:python,单元格,行和列,number,value,cell,column,row From: https://www.cnblogs.com/FBGG/p/17300415.html