0

Please take a look at the file sample.xls clcik here

I was using Apache-Poi to read xls files and convert them into HTML table format.

For few files the POIFSFileSystem (inputStream) could not take the inputStream. There is an exception and it is:

java.io.IOException: Unable to read entire header; 36 bytes read; expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlock.alertShortRead(HeaderBlock.java:226)
at org.apache.poi.poifs.storage.HeaderBlock.readFirst512(HeaderBlock.java:207)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
at openReports.ReadExcelSheet.readExcelFile(ReadExcelSheet.java:24)
at openReports.ReadFolderInMail.getDetailsOfMail(ReadFolderInMail.java:109)
at openReports.ReadFolderInMail.getDetailsOfMail(ReadFolderInMail.java:104)
at openReports.OpenReportsProject.main(OpenReportsProject.java:55)

I could notice, that is because of the file which is saved as xls file but the file format is not 2003. I get these files from a different source,hence I cannot manually change the file extensions. If I download them and change them then the problem is resolved. But I cannot do it every time because it should be run as a scheduler.

So can someone please suggest a solution to this.

Thank you.

7
  • Did you intentionally write "xlx"? Or is it supposed to be "xls"? You say it's not in the Excel 2003 file format. But what format is it? Commented Nov 19, 2011 at 9:29
  • No no sorry its xls.. I suppose it is 2007 format with just extension changed. So when i open it maually it says. The file which you are trying to open is in a indifferent format than specified by the file extension. Commented Nov 19, 2011 at 9:41
  • In order to help you, we need more information about the actual file format. Please either investigate it yourself or post a hex dump of the start of the file in your question. Commented Nov 19, 2011 at 10:40
  • Please take a look at the file. Use slow donload option at end of page and please help. I coudnt find any other file uploads am very new. Please take some time thankyou. I gave a hyperlink at hte top of post Commented Nov 19, 2011 at 13:31
  • I'm sorry but I'm not able to download the sample file. The download hangs even though it's supposed to be just about 20 bytes (?!) long. It's an awful web site anyway. Commented Nov 19, 2011 at 18:12

2 Answers 2

1

You should switch from using the HSSF usermodel to the SS usermodel in POI. It is capable of reading/writing both XLS and XLSX files. I don't think you can use it with POIFileSystem, but you can still read in the excel files without using that class.

Sign up to request clarification or add additional context in comments.

5 Comments

There are very few examples on it. And i have read that SXSSf is only used to write to a file.. Is it true ? Cant we read from it?
You can read a file too... Check out the "XFFS and SAX (Event API)" section of this page: poi.apache.org/spreadsheet/how-to.html#user_api
Should i use the new version jar. I ma using poi-2.0V jar.. It gives some errors while running it. Could u please help on the jar file to use. Thanku :)
Thanyou very much for you time and help. It helped me.
I think you mean the Common SS usermodel - that's what can transparently handle reading and writing both xls and xlsx files. SXSSF only supports writing .xlsx files (in a low memory way)
1

Two possible solutions:

  • if your excel file is .xls then try org.apache.poi.hssf package
  • if your excel file is .xlsx then try org.apache.poi.xssf package

hssf is use for .xls format file and xssf is use for .xlsx

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.