2

Hi I am very new to python, here i m trying to open a xls file in python code but it is showing me some error as below.

Code:

from xlrd import open_workbook
import os.path
wb = open_workbook('C:\Users\xxxx\Desktop\a.xlsx')

Error:Traceback (most recent call last):
File "C:\Python27\1.py", line 3, in <module>
wb = open_workbook('C:\Users\xxxx\Desktop\a.xlsx')
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 429, in open_workbook
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 1545, in getbof
bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
File "C:\Python27\lib\site-packages\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'

need help guyz

4 Answers 4

1

This is a version conflict issue. Your Excel sheet format and the format that xlrd expects are different. You could try to save the Excel sheet in a different format until you find what xlrd expects.

Sign up to request clarification or add additional context in comments.

Comments

0

Not familiar with xlrd, but nothing wrong appears on my Mac.
According to @jewirth, you can try to rename the suffix to xls which is the old version, and then reopen it or convert it into xlsx.

Comments

0
 from xlrd import open_workbook
    import os.path
    wb = open_workbook(r'C:\Users\XXXX\Desktop\a.xlsx')
    print wb
Output : <xlrd.book.Book object at 0x0260E490>

Opened the excel in 'r' format and it shows the excel object. Its working normally. Try to get the xlrd version and update it. Change the excel file format to '.xls' from '.xlsx' and try

Comments

0

You are getting that error because you are using an old version of xlrd which doesn't support xlsx.

You need to upgrade to a recent version of xlrd.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.