Reputation: 97
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
Upvotes: 2
Views: 4407
Reputation: 41524
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.
Upvotes: 0
Reputation: 202
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
Upvotes: 0
Reputation: 31
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.
Upvotes: 0
Reputation: 17460
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.
Upvotes: 1