Search code examples
pythonexcelxlrd

XLRDError: Expected BOF record '\x03OPC '


Is there an easy way to find out what the BOF record, error messages means? A list or something like that where they can be looked up?

I have just installed XLRD 0.9.2, in addition to XLutils 1.6.0 . (I know it's an overkill, so can that might be the problem?) I am reading through a huge bunch of Excel files, where I know that all are excelfiles, at least in their filename.

The errormessage seems to show even though I've put up a Try, Except test. Here's the code where the error shows:

def locate_vals():
    val_dict = {}
    Fcount = 0
    for filename in file_list:
        try:
            wb = xlrd.open_workbook(os.path.join(start_dir, filename))
            sheet = wb.sheet_by_index(5)    # kan ogsaa velge sheet_by_name('navn')
 #             model = sheet.cell_value(2, 3)
            lenghtvalue = sheet.cell_value(9, 7)       # (y,x)
            dispvalue = sheet.cell_value(15, 7)
            try:
                Froudemax = max(Fdict.get(filename)[Fcount - 1], key=str)
                 Froudemin = min(Fdict.get(filename)[Fcount - 1])
                Fcount += 1
            except:
                Froudemax = 5555555555555555555555555555
                Froudemin = 6666666666666666666666666666
                 print 'Froudemax(5) eller Froudemin(6) har problem'
            val_dict[filename] = [lenghtvalue, dispvalue, Froudemax, Froudemin]

        except XLRDError and IndexError:
             print 'Problem in locate_vals with:', filename
    return val_dict
val_dict = locate_vals()

My errormessage says:

Traceback (most recent call last):
  File "C:\Documents and Settings\OPC\My Documents\Haavard_Refvik_Workspace\STT_ComparisonTool\Run_Comparison_Tool.py", line 129, in <module>
     val_dict = locate_vals()
  File "C:\Documents and Settings\OPC\My Documents\Haavard_Refvik_Workspace\STT_ComparisonTool\Run_Comparison_Tool.py", line 111, in locate_vals
    wb = xlrd.open_workbook(os.path.join(start_dir, filename))
   File "C:\Python27\lib\site-packages\xlrd-0.9.2-py2.7.egg\xlrd\__init__.py", line 435, in open_workbook
    ragged_rows=ragged_rows,
  File "C:\Python27\lib\site-packages\xlrd-0.9.2-py2.7.egg\xlrd\book.py", line 91, in open_workbook_xls
     biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
  File "C:\Python27\lib\site-packages\xlrd-0.9.2-py2.7.egg\xlrd\book.py", line 1258, in getbof
    bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
   File "C:\Python27\lib\site-packages\xlrd-0.9.2-py2.7.egg\xlrd\book.py", line 1252, in bof_error
    raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\x03OPC    '

EDIT: OPC is the username on the computer.


Solution

  • Added a try:, except: test, and found the files that caused the problem. Seemed like it was some old "automatic-security-save-files" that had been saved in the same folder as the rest of my files, but where hidden. The name of these files looked like this:

    ~$test spreadsheet modelxxx.xlsx

    I should of course have ran the test earlier, but I had put the Try function a indent too far left, so I never got to see the file that held the error. Thanks for the response.

    I would still appreciate if anyone could point me in the direction of a table of error-messages though, if such a table exists.