python3 使用 xlrd 库操作 excel.xlsx 时,报错: xlrd.biffh.XLRDError: Excel xlsx file; not supported

1、报错

python3 使用 xlrd 库读取 excel 的xlsx 格式的文件时,报错: xlrd.biffh.XLRDError: Excel xlsx file; not supported

代码很简单,xlrd 使用最新版本 2.0.1。

2、原因

通过网络搜索,得知 xlrd 扩展版本有变化同,xlrd官网: https://pypi.org/project/xlrd/#description 有提到:This library will no longer read anything other than .xls files. For alternatives that read newer file formats, please see http://www.python-excel.org/ , xlrd 从2.X版本开始只支持.xls格式的EXCEL文件 ,不支持其它的。其它的文件可看前面的链接中的其它模块,比如 openpyxl,xlsxwriter,pylightxl 。

总结起来如下:

版本 支持
xlrd 1.2 支持 .xls 、 .xlsx 文件
xlrd 2.0 只支持.xls文件

3、解决方法

卸载 高版本的 V2.0.1 的 xlrd,安装 低版本 V1.2.0 的 xlrd。

pip uninstall xlrd
pip install xlrd==1.2.0

猜你喜欢

转载自blog.csdn.net/xiaojin21cen/article/details/125202667