python xlwt 解决报错:ValueError: More than 4094 XFs (styles)
解决方案
对于设置样式的函数:
def define_style():font = xlwt.Font()font.colour_index = 1# 初始化样式my_style = xlwt.XFStyle()my_style.font = font # 设置字体return my_style
写入数据时,不要使用sheet.write(0, 0, '数据', define_style())
这种方式,改为:
mystyle = define_style() # 把样式函数赋值
sheet.write(0, 0, '数据', mystyle) # 在写入数据时不调用函数,而是传入值
例子分析
如下代码会报错
import xlwtdef define_style():font = xlwt.Font()font.colour_index = 1# 初始化样式my_style = xlwt.XFStyle()my_style.font = font # 设置字体return my_styleif __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()) # 注意这里的 define_style() !!!!!!!book.save('my_excel.xlsx')
修改main函数
里的局部为:
mystyle = define_style()for i in range(10000):sheet.write(i, 0, u'(0,0)', mystyle) # 这里使用 mystyle
原因解析
在使用xlwt
写入数据时,在传入XFStyle
格式的样式时,不要使用匿名函数
调用写入,否则写入4094个数据后就会超过阈值,报错:ValueError: More than 4094 XFs (styles)
python xlwt 解决报错:ValueError: More than 4094 XFs (styles)相关推荐
- 已解决ValueError: More than 4094 XFs (styles)
已解决(Python xlwt写入Excel样式报错)ValueError: More than 4094 XFs (styles) 文章目录 报错代码 报错翻译 报错原因 解决方法 报错代码 我的代 ...
- 解决python读取pickle报错ValueError: unsupported pickle protocol: 5
解决方法 换一个python3.8+的版本读取pkl文件的数据 保存为其他格式或低版本的pkl,保存时设置protocol关键字即可 问题解析 这是因为保存为.pkl文件时使用的协议号为5(pytho ...
- pyculiarity解决报错ValueError: data must be a 2 column data.frame, with thefirst column...
解决方法 报错全称为:ValueError: data must be a 2 column data.frame, with thefirst column being a set of times ...
- dataframe 添加列表到一个单元格并解决报错ValueError: Must have equal len keys and value when setting with an...
报错解析 import pandas as pd import numpy as npdf = pd.DataFrame(np.random.randint(0,10,size=(5, 2)),col ...
- python如何解决报错:‘platformVersion’ must be of type string
1.yaml文件写的是: platformVersion: 10 2.driver初始化: data = yaml.load(file, Loader=yaml.FullLoader) desired ...
- python selenium解决报错SessionNotCreatedException session not created: No matching capabilitie与问题解析
解决方法 查看导包是否正确: 如果是webdriver.Chrome,那么导包的一切都要是chrome的 如果是webdriver.Firefox,那么导入的包也都源于firefox的包 出现这个问题 ...
- python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call
python调用dll报错:ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong call ...
- python导入openpyxl报错问题,终于解决啦
python导入openpyxl报错问题,终于解决啦 参考文章: (1)python导入openpyxl报错问题,终于解决啦 (2)https://www.cnblogs.com/guotang/p/ ...
- Python 中文注释报错解决方法
Python 中文注释报错解决方法 参考文章: (1)Python 中文注释报错解决方法 (2)https://www.cnblogs.com/cjiong/p/5881983.html 备忘一下.
最新文章
- 四管前级怎么去掉高低音音调_TDG Audio达芬奇:什么是前级,后极?
- .Net程序员安卓学习之路5:使用xutils注入View和事件以及图片的显示
- python做excel数据分析统计服_Python也能做到Excel那样,条件统计轻松解决工作需求...
- 代码注释掉还能执行_日志消息是可执行代码和注释
- php做一个微信退款,PHP实现微信申请退款流程实例代码
- USACO翻译:USACO 2012 FEB Silver三题
- 国内外研究主页集合:计算机视觉-机器学习-模式识别
- python棋盘放米问题_Python基于回溯法子集树模板解决马踏棋盘问题示例
- 小学 学生学籍信息汇总及自动检查代码(Python)
- Qt更改字体为思源黑体
- 使用频谱仪测试信号抗干扰实验
- hyperledger fabric 2.3.3 环境搭建教程
- Linux环境下安装MySQL(源码安装)
- KeyStore加载PublicKey/PrivateKey(公/私钥)证书
- 很多做淘宝客的朋友会用到采集,那么怎么提取出淘宝商品id呢
- 许昌一高2021年高考成绩查询,2021年许昌最好的高中排名,许昌重点高中升学率排名...
- 千年古茶树生嫩芽 散茶香
- 一次破解TP-Link WAR308路由器的经历
- Android - 框架使用
- vue2+vue3——36+
热门文章
- sqlite3.OperationalError: no such column: **
- 与计算机密度密切相关的是,全国计算机二级MS考前冲刺试题及答案2016
- 【音效处理】Vibrato 简介
- 高擎信息安全大旗,打造“互联网+”新服务模式
- Apache Ant 简介和配置
- 安全领域多位世界级权威的智慧结晶——《黑客新型攻击防范:深入剖析犯罪软件》...
- 特征码的使用办法_小脚的美丽与哀愁,34/35码的她们都是怎么买鞋的?
- 剪切粘贴时总是上次的内容_关于复制粘贴,还有一个鲜为人知的技巧!
- linux下解压命令.7z,CentOS 下安装7-Zip 以及常用的解压命令
- java字符后移_java把字符串参数往后移3位后输出