Openpyxl.utils.exceptions.IllegalcharacterError

发布于 2021-01-29 16:35:03

我有以下python代码将处理过的单词写入excel文件。这个词大约是7729

From openpyxl import *
book=Workbook ()
sheet=book.active
sheet.title="test"
for x in range (7729):
    sheet.cell (row=1,column=x+1).value=x
book.save ('test.xlsx')

这是我使用的代码的样子,但是当我运行它时,它给了我一个错误,指出

openpyxl.utils.exceptions.IllegalCharacterError

这是我第一次使用此模块,我将不胜感激。

关注者
0
被浏览
49
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    试试看: 此代码对我有用。

    from openpyxl import *
    book=Workbook ()
    sheet=book.active
    sheet.title="test"
    x = 0
    with open("temp.txt") as myfile :
        text = myfile.readline()
        while text !="":
                sheet.cell (row=1,column=x+1).value=str(text).encode("ascii",errors="ignore")
                x+=1
                text = myfile.readline()
    
    book.save ('test.xlsx')
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看