Solution
For style setting functions:
def define_style():
font = xlwt.Font()
font.colour_index = 1
my_style = xlwt.XFStyle()
my_style.font = font
return my_style
When writing data, do not use sheet.write (0, 0, 'data', define)_ Style ())
in this way, change to:
mystyle = define_style()
sheet.write(0, 0, 'data', mystyle)
Example analysis
The following code will report an error
import xlwt
def define_style():
font = xlwt.Font()
font.colour_index = 1
my_style = xlwt.XFStyle()
my_style.font = font
return my_style
if __name__ == '__main__':
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
# mystyle = define_style()
for i in range(10000):
sheet.write(i, 0, u'(0,0)', define_style())
book.save('my_excel.xlsx')
Modify the part in main function
as follows:
mystyle = define_style()
for i in range(10000):
sheet.write(i, 0, u'(0,0)', mystyle)
Reason analysis
When using xlwt
to write data, when passing in the style of xfstyle
format, do not use anonymous function
to call to write, otherwise after writing 4094 data, it will exceed the threshold, and an error will be reported: valueerror: more than 4094 XFS (styles)
Read More:
- [Solved] ValueError: row index was 65536, not allowed by .xls format
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Solved] ValueError: only one element tensors can be converted to Python scalars
- Python Valueerror: cannot index with vector containing Na / Nan values
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- Python: How to Solve error While importing windpy
- Python: How to Solve multiprocessing module Error in Windows
- How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’
- [Solved] python Error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- Python: How to Solve mysqlclient Install Error in Mac
- How to Solve Python3.9 Install pycrypto Error
- How to Solve Python picamera and raspistill error
- How to Solve Python Libsm. So. 6 error
- How to Solve Python ImportError: cannot import name UnrewindableBodyError
- How to Solve Python ShapeFile.writer Error for Beginners
- Python 3.X error: valueerror: data type must provide an itemsize
- How to Solve Python Importerror: DLL load failed: unable to find the specified program using tensorflow
- How to Solve Python Pandas Read or Import Files Error
- Python ValueError: only 2 non-keyword arguments accepted