Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

excel - python xlrd unsupported format, or corrupt file.

My code:

import xlrd
wb = xlrd.open_workbook("Z:\Data\Locates\3.8 locates.xls")
sh = wb.sheet_by_index(0)
print sh.cell(0,0).value

The error:

Traceback (most recent call last):
File "Z:WilsonradedStockStatus.py", line 18, in <module>
wb = xlrd.open_workbook("Z:\Data\Locates\3.8 locates.xls")
File "C:Python27libsite-packagesxlrd\__init__.py", line 429, in open_workbook
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:Python27libsite-packagesxlrd\__init__.py", line 1545, in getbof
bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
File "C:Python27libsite-packagesxlrd\__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 '<table r'"

The file doesn't seem to be corrupted or of a different format. Anything to help find the source of the issue would be great.

question from:https://stackoverflow.com/questions/9623029/python-xlrd-unsupported-format-or-corrupt-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You say:

The file doesn't seem to be corrupted or of a different format.

However as the error message says, the first 8 bytes of the file are '<table r' ... that is definitely not Excel .xls format. Open it with a text editor (e.g. Notepad) that won't take any notice of the (incorrect) .xls extension and see for yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...