I have the following code to write processed words into excel file. The words are about 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')
This is the code I used looks like. But when I run it it gives me an error that says
openpyxl.utils.exceptions.IllegalCharacterError
This is my first time using this module, I would appreciate any kind of help.
Try this : This code works for me .
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')
You missed to add the value for cell sheet.cell (row=1,column=x+1).value =
Try like this
from openpyxl import *
book = Workbook ()
sheet = book.active
sheet.title = "test"
for x in range (7):
sheet.cell (row=1,column=x+1).value = "Hello"
book.save ('test.xlsx')
来源:https://stackoverflow.com/questions/49844925/openpyxl-utils-exceptions-illegalcharactererror