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 个回答
-
试试看: 此代码对我有用。
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')