Pandas.read_excel:不支持的格式,或损坏的文件:预期的 BOF 记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45700658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 04:15:14  来源:igfitidea点击:

Pandas.read_excel: Unsupported format, or corrupt file: Expected BOF record

pythonexcelpandasxlrd

提问by DLee

I'm trying to use pandas.read_excel to read in .xls files. It succeeds on most of my .xls files, but then for some it errors out with the following error message:

我正在尝试使用 pandas.read_excel 读取 .xls 文件。它在我的大多数 .xls 文件上都成功了,但是对于某些文件,它会出错并显示以下错误消息:

Unsupported format, or corrupt file: Expected BOF record; found '\x00\x05\x16\x07\x00\x02\x00\x00'

I've been trying to research why this is happening to some, but not all files. The xlrd version is 1.0.0. I tried to manually read in with xlrd.open_workbook and I get the same result.

我一直在努力研究为什么这会发生在一些文件上,但不是所有文件。xlrd 版本是 1.0.0。我尝试使用 xlrd.open_workbook 手动读入,但得到了相同的结果。

Does anyone know what file type, this BOF record is referring to?

有谁知道这个BOF记录指的是什么文件类型?

回答by Naufal

There are various reasons to why that error message appeared. However, the main reason could be due to the Excel file itself. Sometimes, especially if you're pulling an Excel file from some Reporting Portal, the Excel file could be corrupt so the best thing would be to open the Excel file and save it as a new .xls file then retry running pandas.read_excel.

出现该错误消息的原因有多种。但是,主要原因可能是由于 Excel 文件本身。有时,尤其是当您从某个报告门户中提取 Excel 文件时,Excel 文件可能已损坏,因此最好的方法是打开 Excel 文件并将其另存为新的 .xls 文件,然后重试运行 pandas.read_excel。

Lemme know if it works.

让我知道它是否有效。