Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

java.io.IOException: Invalid header signature; read 0x000201060000FFFE, expected 0xE11AB1A1E011CFD0

when trying to add some custom properties to an Excel document using apache POI HPSF.

I'm completely sure the file is Excel OLE2 (not HTML, XML or something else that Excel doesn't complain about).

This is a relevant part of my code:

try {
     final POIFSFileSystem poifs = new POIFSFileSystem(event.getStream());
     final DirectoryEntry dir = poifs.getRoot();
     final DocumentEntry dsiEntry = (DocumentEntry)
             dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
     final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
     final PropertySet props = new PropertySet(dis);
     dis.close();
     dsi = new DocumentSummaryInformation(props);
    catch (Exception ex) {
        throw new RuntimeException
            ("Cannot create POI SummaryInformation for event: " + event +
              ", path:" + event.getPath() + 
              ", name:" + event.getPath() +
              ", cause:" + ex);

I get the same error when trying with word and power point files (also OLE2).

I'm completely out of ideas so any help/pointers are greatly appreciated :)

If you have the same error (or similar), make sure the file is actually an excel file, otherwise it will not open with POI. It should either be OLE2 format or DOCX. To be sure its one of those formats open the file in excel and 'save as' some excel format from the menu. – Simeon Nov 22, 2010 at 8:31

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.

Is there any description/ list of values for valid header signatures? That would help is identifying the specific issue as I encountered a similar error with following values:- read 4503599627764233, expected -2226271756974174256 – s khan Nov 29, 2012 at 9:23 There is only one valid signature, everything else is incorrect. Try using Apache Tika to detect what your file really is if you don't know – Gagravarr Nov 29, 2012 at 9:43

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.

No I'ts not I created it by hand and I'm sure its OLE2. As I said in my question :) "I'm completely sure the file is excel OLE2 (not HTML, XML or something else that excel doesn't complain about)." – Simeon Nov 22, 2010 at 8:28

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 :-)

Could you expand this answer a bit more? As it stands, it doesn't really seem to answer the question that was originally asked... – Gagravarr Jan 21, 2013 at 17:24

I was using the .xlsx file instead of .xls. We have to use the .xls file if we are using Workbook, Sheet and Row classes. My file was .xlsx, that created this issue and I changed it to .xls, it worked.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.