这是我的.xslx文件:
from openpyxl import load_workbook
workbook = load_workbook('/path/', read_only=True)
first_sheet = workbook.sheetnames()[0]
worksheet = workbook[first_sheet]
for row in worksheet:
for cell in row:
print(cell.value)
如何从A4开始迭代?我需要打印year
和month
值。
答案 0 :(得分:0)
您可以通过指定偏移量或范围
来使用iter_rows
T
顺便说一下:for row in worksheet.iter_rows('A4:B9'):
for cell in row:
print(cell.value)
应为sheetnames()[0]
或sheetnames[0]