#在Excel表中进行关键词查找
import openpyxl
def search_excel_file(file_path, keyword):
# 打开 Excel 文件
workbook = openpyxl.load_workbook(file_path)
# 获取第一个工作表
sheet = workbook.active
# 遍历每行数据
for row in sheet.iter_rows():
# 遍历每个单元格
for cell in row:
# 如果单元格的值包含关键字
if keyword in str(cell.value):
# 返回该单元格所在的行和列号
return f"Found '{keyword}' at {cell.column_letter}{cell.row}"
# 如果未找到关键字,返回提示信息
return f"Could not find '{keyword}' in file."
# 测试
file_path = "微信支付账单(20230319-20230419).xlsx"
keyword = "A205田利坤"
result = search_excel_file(file_path, keyword)
print(result)
#————————————————
#版权声明:本文为CSDN博主「字节跳远」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
#原文链接:https://blog.csdn.net/m0_73291751/article/details/129165898
小黑屋|Archiver|手机版|su.sseuu.com ( 粤ICP备12005776号 )
GMT+8, 2024-10-15 18:12 , Processed in 0.426431 second(s), 18 queries .
Powered by Discuz! X3.4 Licensed
© 2001-2013 Comsenz Inc.