openpyxl режим только для чтения не может iter_cols - PullRequest
1 голос
/ 03 мая 2020

У меня есть большой файл Excel, который я хочу перебрать по столбцам. Поскольку это большой файл Excel, я должен использовать режим только для чтения в openpyxl, а iter_cols недоступен в этом режиме. Как я могу переписать этот код без использования iter_cols? Вот мой код:

def CheckTag(min_col, max_col):
    for col_cells in sheet.iter_cols(min_col=min_col, max_col=max_col):
        for cell in col_cells:
            cell_obj_str = str(cell)
            if (cell.value in tags or cell_obj_str[-2:] == "1>"):
                print("PASS", cell_obj_str[-2:])
            else:
                cell_obj_str = str(cell)
                errors_file.write(cell_obj_str + "Tag is Wrong\r\n")

1 Ответ

0 голосов
/ 03 мая 2020

Вы можете преобразовать его в прямой доступ к ячейке:

def CheckTag(min_col, max_col):
    for col in range(min_col, max_col+1):
        for row in range(1, sheet.max_row+1):
            cell = sheet.cell(col, row)
            ...  # rest of code stays the same
...