1

I am trying to extract data from an excel file and unfortunately the xlrd library documentary is not opening up the file and it is throwing a lot of errors. For reference, I have a .xls file with 10+ pages of data

I've tried to use the xlrd library with no luck, here is my code:

import xlrd

file = "C:\TestAutomation\doc\Smart_CID.xls"

wb = xlrd.open_workbook(file)

print(wb.nsheets)

Here is the Traceback:

Traceback (most recent call last):
  File "C:/TestAutomation/src/XML_parser.py", line 7, in <module>
    wb = xlrd.open_workbook(file)
  File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 157, in open_workbook
    ragged_rows=ragged_rows,
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 92, in open_workbook_xls
    biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 1278, in getbof
    bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 1272, in bof_error
    raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '<?xml ve'

For other reference, this excel file gets generated from a company website and it creates an excel file as well as an xml file. How can I open this excel file ?

SaturnsBelt
  • 271
  • 2
  • 13

1 Answers1

2

I believe the file might not in proper xls form. Open the file in notepad to check. The "?xml ve" indicates that.

See this post for a similar situation.

Your file is probably really a .xml file, which is not supported by xlrd.