from openpyxl import load_workbook
wb = load_workbook("test.xlsx")
all_sheets = wb.get_sheet_names()
print(all_sheets)
for i in range(len(all_sheets)):
sheet = wb.get_sheet_by_name(all_sheets[i])
print(sheet.title + ': max_row: ' + str(sheet.max_row) + ' max_column: ' + str(sheet.max_column))
sheet = wb.get_sheet_by_name(all_sheets[0])
for row in sheet.iter_rows():
for cell in row:
if cell.value is not None:
info = cell.value.find('BB')
if info == 0:
print(cell.value)
python_excel_openpyxl_成功实现遍历表格并取得数字
最新推荐文章于 2024-04-20 14:51:35 发布
本文档展示了如何使用Python库openpyxl操作Excel文件,包括读取所有工作表名称、获取每个工作表的最大行数和列数,并搜索指定字符串。重点在于通过`get_sheet_by_name`遍历和内容查找功能。
1086





