Error in converting txt to xlsx using python

让人想犯罪 __ 提交于 2019-12-02 01:01:18

Seems like you are using openpyxl 2.0.0 + ,according to changelog for Openpyxl 2.0.0 -

Cells are referenced with 1-indexing: A1 == cell(row=1, column=1)

The rows and columns index start at 1. So you should make your enumerate() function start at 1 as well. Example -

    for row_index, row in enumerate(reader, 1):
        for col_index, value in enumerate(row, 1):
            ws.cell(row=row_index, column=col_index).value = value

Your particular code would work in openpyxl version less than 2.0.0 , it fails because of the above mentioned change in version 2.0.0 .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!