python - XLRDError : Unsupported format, 或损坏的文件:预期的 BOF 记录;

标签 python xlrd

我正在尝试通过 xlrd 打开工作簿。

import xlrd
workbook=xlrd.open_workbook("D:\Book1.xlsx")

但这是抛出如下错误:

Traceback (most recent call last):
File "C:\Users\testuser\Documents\NetBeansProjects\NewPythonProject\src\newpythonproject.py", line 18, i`enter code here`n <module>
workbook=xlrd.open_workbook("D:\Book1.xlsx")


File "D:\xlrd-0.7.1\xlrd\__init__.py", line 429, in open_workbook
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)


File "D:\xlrd-0.7.1\xlrd\__init__.py", line 1545, in getbof
bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])


 File "D:\xlrd-0.7.1\xlrd\__init__.py", line 1539, in bof_error
raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found 'PK\x03\x04\x14\x00\x06\x00'

我在带有 python 插件的 netbeans 中运行它。如果 xlrd 的版本是问题,我需要一个链接以在 Windows 中下载最新版本的 xlrd。帮我解决这个问题。

最佳答案

看起来您正在使用相当旧的 xlrd-0.7.1 - 最新版本是 xlrd-0.9.3。我的测试显示0.7.1无法打开0.9.3可以打开的.xlxs文件,所以是时候升级了。

您可以从 PyPI 获取它:xlrd-0.9.3 .我认为 MSI 不可用,但您应该能够通过先解压缩 tarball 然后运行 ​​python setup.py install 来安装它。

关于python - XLRDError : Unsupported format, 或损坏的文件:预期的 BOF 记录;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25987067/

相关文章:

python - 从雅虎财经论坛提取回复

python - Numpy:从 4D 数组中切片 3D 数组?

python - 如何使用python获取excel表中的行号?

python - 如何通过 xlwt 获取 Excel 文件中的行数

Python - XLRDError : Unsupported format, 或损坏的文件:预期的 BOF 记录

python - Pandas 中的多索引排序

c++ - 糟糕 : the __cmp__ function

python - nginx gunicorn 502 坏网关 : upstream prematurely closed connection while reading response header from upstream

python - 将 Excel 的列转换为 python 中的字典

Python2.7 : Syntax error while using print sheet values with a script