python openpyxl read excel too slow

后端 未结 2 1363
暖寄归人
暖寄归人 2021-01-29 08:37

I have a .xlsx file, owning 1841 rows. Each row has 30 columns.Use openpyxl saving the whole info to a list.

def get_value(i,ws,article_row):
    value=ws.cell(         


        
相关标签:
2条回答
  • 2021-01-29 09:11

    The problem is related to the extensive use of the cell method in read-only mode. In read-only mode openpyxl reads the relevant worksheet on-demand to reduce memory use low but means that for every lookup the XML will be parsed again. The code you have rewritten forces openpyxl to reparse the file for every cell in every row which is obviously slow. This is also entirely unnecessary because there is an API for row-based access. Just use ws.iter_rows() with the relevant delimiters to get cells you want.

    0 讨论(0)
  • 2021-01-29 09:12

    You can use xlwings. It's very fast and easy to use.

    0 讨论(0)
提交回复
热议问题