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

报错如下: 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

最近更新

  1. TCP协议是安全的吗?

    2024-02-23 15:50:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-23 15:50:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-23 15:50:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-23 15:50:03       20 阅读

热门阅读

  1. win10彻底解决IE浏览器自动跳转edge问题

    2024-02-23 15:50:03       25 阅读
  2. 在Vue3 + Vite项目中使用less

    2024-02-23 15:50:03       30 阅读
  3. 爬虫项目(1)

    2024-02-23 15:50:03       28 阅读
  4. ffmpeg静态编译 —— 筑梦之路

    2024-02-23 15:50:03       37 阅读