簡體   English   中英

openpyxl 只讀模式不能 iter_cols

[英]openpyxl read-only mode cannot iter_cols

我有一個大的 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")

您可以將其轉換為直接單元格訪問:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM