从特定列开始迭代

时间:2016-06-13 10:33:42

标签: python openpyxl

这是我的.xslx文件:

data.xlsx

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开始迭代?我需要打印yearmonth值。

1 个答案:

答案 0 :(得分:0)

您可以通过指定偏移量或范围

来使用iter_rows
T

顺便说一下:for row in worksheet.iter_rows('A4:B9'): for cell in row: print(cell.value) 应为sheetnames()[0]sheetnames[0]