python:xlrd.biffh.XLRDError: Excel xlsx file; not supported

1. 问题描述

LZ使用xlrd读取file.xlsx的文档时,运行程序报错

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/root/.pycharm_helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/root/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/fanrongrong/sentence-transformers/examples/transformers_tour/test_data/xlsx2txt.py", line 3, in <module>
    workbook = xlrd.open_workbook('./jqsj.xlsx')
  File "/root/anaconda2/envs/SentenceTrans3.9/lib/python3.9/site-packages/xlrd/__init__.py", line 170, in open_workbook
    raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported

2. 解决方案

就离谱,居然不支持xlsx格式,最终在各种百度之下,找到了解决方案,居然是降版本!

conda install  xlrd==1.2.0
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.9.1
  latest version: 4.10.1

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /root/anaconda2/envs/SentenceTrans3.9

  added / updated specs:
    - xlrd==1.2.0


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    xlrd-1.2.0                 |             py_0         103 KB  defaults
    ------------------------------------------------------------
                                           Total:         103 KB

The following packages will be DOWNGRADED:

  xlrd                                   2.0.1-pyhd3eb1b0_0 --> 1.2.0-py_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
xlrd-1.2.0           | 103 KB    | ############################################################################################################################################################# | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

最后运行程序,问题解决,这个版本更新的意义是?

当你遇到 "xlrd.biffh.XLRDError: Excel xlsx file; not supported" 错误时,这意味着你正在尝试使用xlrd库读取一个不受支持的xlsx文件格式。这个错误可能是由于以下几个原因导致的: 1. 文件格式不正确:你的文件可能不是真正的xlsx格式文件,而是以xlsx为扩展名的其他类型的文件。你可以尝试使用文本编辑器打开该文件并查看内容,确保它是一个有效的xlsx文件。 2. xlrd版本不兼容:你可能使用了一个不兼容的xlrd版本。你可以尝试降低xlrd的版本,例如安装1.2.0版本。你可以通过终端使用以下命令卸载当前版本并安装1.2.0版本: ``` pip uninstall xlrd pip install xlrd==1.2.0 ``` 3. Excel文件的版本过高:你的Excel文件可能使用了一个过高的版本。你可以尝试将该文件另存为xls格式,然后再尝试使用xlrd读取该文件。你可以按照以下步骤进行操作: - 在包含错误的Excel文件的文件夹中创建一个新的Excel文件,并将其命名为"new.xls"(名称可以自定义,但后缀必须为xls)。 - 将错误文件中的数据复制到"new.xls"中。 希望以上解决方法能够帮助你解决问题。如果问题仍然存在,请提供更多细节,以便我能够更好地帮助你。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [读取xlsx文件错误:xlrd.biffh.XLRDError: Excel xlsx file; not supported](https://blog.csdn.net/Erickkkkkk/article/details/124696751)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [解决python xlrd无法读取excel文件的问题](https://download.csdn.net/download/weixin_38606019/14912490)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [xlrd.biffh.XLRDError: Excel xlsx file; not supported,两种解决方案](https://blog.csdn.net/sinat_37868031/article/details/113376079)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值