Skip to content

XLS – 2003 – XML format

November 2, 2011

It is an interesting problem atleast for me.

We need to develop a utility (due to the business / data constraints) which can merge XLS files.

Started with the read / write using Apache POI using HSSF and XSSF.

Wrote the code and i was happy that the utility can be completed in few more days.

Today, tested that one with the sample XLS given by my team mate and found that it is neither XSSF nor HSSF.

To my surprise, i was able to open the XLS file in a notepad and it has XML contents.

I was getting the following exceptions

  • Exception in thread “main” java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
  • Exception in thread “main” org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

After some googling, got the following reference.

http://apache-poi.1045710.n5.nabble.com/How-to-convert-xml-to-xls-td2306602.html

The highlighted information is

You have got an Office 2003 xml file there, not an OpenXML file; it is an early attempt by Microsoft to create an xml based file format for Excel and it is in that sense a ‘valid’ Office file format.

Sadly, POI cannot interpret this file at all and that is why you saw the exception when you tried to wrap it up in the InputStream and pass it to WorkbookFactory(s) constructor
This is one of the significant learning for me today…

Meet you soon….. 🙂

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: