title: Issues with excel file. XLRDError: Unsupported format, or corrupt file: What kind of file is this?
body: <p>I have a bit of code that works with an xls file. It works for everything I've thrown at it except this one file and I don't know how to properly identify what this one file is. I get the file off of a website I am navigating with Selenium. This particular spreadsheet always downloads as a file type that causes this error.  </p>
  
  <p>The full error is:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/Meir/Documents/PYTHON/IFG User Update/code/ifg_TPA_update_excel.py", line 44, in &lt;module&gt;
      rb = open_workbook((os.path.expanduser("~/Documents/PYTHON/Selenium test/TPA_Example.xls")),formatting_info=True)
    File "/usr/local/lib/python2.7/site-packages/xlrd/__init__.py", line 443, in open_workbook
      ragged_rows=ragged_rows,
    File "/usr/local/lib/python2.7/site-packages/xlrd/book.py", line 94, in open_workbook_xls
      biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
    File "/usr/local/lib/python2.7/site-packages/xlrd/book.py", line 1262, in getbof
      bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
    File "/usr/local/lib/python2.7/site-packages/xlrd/book.py", line 1256, in bof_error
      raise XLRDError('Unsupported format, or corrupt file: ' + msg)
  XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\xff\xfe&lt;\x00S\x00T\x00'
  </code></pre>
  
  <p>The file I am trying to open displays as an xls file in my finder. However, when I open it, it does not open with the file name as the header but rather displays "Workbook1". When I hit save, it opens the save menu as if I had clicked save as, and defaults to "Workbook1.xlsx". I tried changing my code to open it as an xlsx file, but then it errors out saying it cannot find the file. Whenever I try googling it, I don't know how to phrase it to get a relevant answer.  </p>
  
  <p>When I contacted the websites support team asking what kind of file the TPA bulks op sheet is they replied:</p>
  
  <blockquote>
    <p>The TPA bulk ops is an older version than the rest of the bulk ops, it's due to be rebuilt some time later this year.  When downloading the file your best bet is to do a Save As and save it as an older version of .xls, I usually select Microsoft Excel 5.0/95 Workbook, and also format it as text.  Formatted that way it should upload without issue.</p>
  </blockquote>
  
  <p>Any ideas as to how I can open this right from Python?</p>
  
  <p>Currently I am building each part as a separate code and I was going to combine them all together once I get it sorted out. The below is the section of code that will be opening the file and is experiencing the error. </p>
  
  <p>My code:</p>
  
  <pre><code>#!/usr/bin/env python
  ## Import OS and Modules
  import os
  import csv
  import xlrd
  import xlwt
  import xlutils
  import csv
  import collections
  
  ## Define Input File from IFG
  ifg_user_file = "New_PCs_to_set_up_in_marketing_database_-_4-11-2013.csv"
  
  ## Import data
  data = [row for row in csv.reader(open (os.path.expanduser("~/Downloads/" + ifg_user_file),'U'))]
  
  ## Find number of rows
  row_count = sum(1 for row in data)
  print row_count
  ## Set to turn off when reaching the end of data
  end_of_data = False
  
  from xlutils.copy import copy # http://pypi.python.org/pypi/xlutils
  from xlrd import open_workbook # http://pypi.python.org/pypi/xlrd
  from xlwt import easyxf # http://pypi.python.org/pypi/xlwt
  
  ##################################################################################
  ## THE ERROR OCCURS AT THE LINE BELOW 
  rb = open_workbook((os.path.expanduser("~/Documents/PYTHON/Selenium test/TPA_Example.xls")),formatting_info=True)
  r_sheet = rb.sheet_by_index(0) # read only copy to introspect the file
  </code></pre>
  
  <p><strong>EDIT: I tried to open it with codecs rather than open for diagnostics</strong></p>
  
  <pre><code>rb=codecs.open((os.path.expanduser("~/Documents/PYTHON/Selenium test/TPA_Example.xls")), 'r', encoding='utf16');
  print rb;
  print rb.readline();
  print rb.read(20);
  </code></pre>
  
  <p>It printed the following result:</p>
  
  <pre><code>&lt;open file '/Users/Meir/Documents/PYTHON/Selenium test/TPA_Example.xls', mode 'rb' at 0x110fe51e0&gt;
  &lt;STYLE&gt;
  
              .excel { BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px so
  </code></pre>
  
  <p>It looks like it is an excel document then. Not sure how to proceed. <strong>Is there a universal open an excel document command?</strong></p>