0221 解决万得导出数据excel无法python读入的问题

文章讲述了在处理万得导出的带格式xlsx文件时,openpyxl引发TypeError的问题。解决方案是降级到pandas1.3.5版本并使用xlrd引擎处理,确保文件能被成功打开。
摘要由CSDN通过智能技术生成

报错如下: TypeError: <class 'openpyxl.styles.named_styles._NamedCellStyle'>.name should be <class 'str'> but value is <class 'NoneType'>

原因分析:

万得导出的xlsx带有某些格式,比如首行加粗,excel桌面端工具能打开,但openpyxl报错,导致无法批量处理 ,

修改方法:

使用python3.8 安装旧版pandas和xlrd,并在pandas代码中指定引擎使用xlrd

\Python38\Scripts\pip.exe install pandas==1.3.5 -i  https://pypi.tuna.tsinghua.edu.cn/simple

\Python38\Scripts\pip.exe install xlrd=1.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

pd.read_excel(pdf_path, usecols=None, engine='xlrd')

提供解决思路的原文地址:

agileminor commented on Apr 29, 2022

I found a different work around - in pandas 1.3.5 (or earlier) and xlrd version < 2.0, use engine='xlrd' and the ViCell file can be opened successfully.

来自 <BUG: pandas cannot open xlsx with openpyxl engine · Issue #40499 · pandas-dev/pandas · GitHub>

最后使用python38就可以使用了。

C:\Users\charlie\AppData\Local\Programs\Python\Python38\python.exe mergeTables.py

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值