Invalid header signature; IOException with Apache POI on excel document Invalid header signature; IOException with Apache POI on excel document apache apache

Invalid header signature; IOException with Apache POI on excel document


If you flip the signature number round, you'll see the bytes of the start of your file:

0x000201060000FFFE -> 0xFE 0xFF 0x00 0x00 0x06 0x01 0x02 00

The first two bytes look like a Unicode BOM, 0xFEFF means 16 bit little endian. You then have some low control bytes, the hex codes for 0 then 258 then 2, so maybe it isn't a text file after all.

That file really isn't an OLE2 file, and POI is right to give you the error. I don't know what it is, but I'm guessing that perhaps it might be part of an OLE2 file without it's outer OLE2 wrapper? If you can open it with office, do a save-as and POI should be fine to open that. As it stands, that header isn't an OLE2 file header so POI can't open it for you.


In my case, the file was a CSV file saved with the .xls extension. Excel was able to open it without a problem, but POI was not.

If I find a better/more general solution, I'll come back and write it up here.


Try save it as csv file directly and use opencsv for your operations.
Use the following link to know about opencsv.
http://opencsv.sourceforge.net/#what-is-opencsv

Excel can open a csv, xls or even html table saved as xls.

So you can save the file as file_name.csv and can use opencsv for reading the file in your code.

Or else you can the file once in excel by save As excel 97-2003 workbook.

And then, POI itself can read the file :-)