Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unsupported format, or corrupt file: Expected BOF record

Tags:

I am trying to open a xlsx file and just print the contents of it. I keep running into this error:

import xlrd book = xlrd.open_workbook("file.xlsx") print "The number of worksheets is", book.nsheets print "Worksheet name(s):", book.sheet_names() print  sh = book.sheet_by_index(0)  print sh.name, sh.nrows, sh.ncols print  print "Cell D30 is", sh.cell_value(rowx=29, colx=3) print  for rx in range(5):     print sh.row(rx)     print 

It prints out this error

raise XLRDError('Unsupported format, or corrupt file: ' + msg) xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found    '\xff\xfeT\x00i\x00m\x00' 

Thanks

like image 820
user2353003 Avatar asked May 12 '13 07:05

user2353003


People also ask

What is BOF error?

The error message relates to the BOF (Beginning of File) record of an XLS file. However, the example shows that you are trying to read an XLSX file. There are 2 possible reasons for this: Your version of xlrd is old and doesn't support reading xlsx files.


1 Answers

If you use read_excel() to read a .csv you will get the error

XLRDError: Unsupported format, or corrupt file: Expected BOF record;

To read .csv one needs to use read_csv(), like this

df1= pd.read_csv("filename.csv") 
like image 144
Mike Chan Avatar answered Sep 17 '22 15:09

Mike Chan