You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Marwan Gedeon <ma...@zaradoustra.com> on 2008/01/31 19:17:47 UTC

XLS files with no header

I'm running through constraints in the format of an Excel file I have at
hand, as it's being downloaded from a carrier directly.  My application
needs to read the excel file as is without preopening in Excel, then convert
it to CSV. POI fails to open it with the error:

java.io.IOException: Invalid header signature; read 4503629692403721,
expected -2226271756974174256
      at
org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java
:100)
      at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:
84)
      at com.cme.billtools.ExcelReader.main(ExcelReader.java:36)


I have noticed many threads on the net mentioning that the headers can be
set through the contenttype, but I do not have control over the carrier's
website to do that. 
So my other alternative is to preprocess the Excel file in java to insert
headers, then save it, and reopen it with POI.  However, I do not see any
information on doing that through the API docs. Particularly, I do not know
how to manipulate the different blocks. 
If anyone has some insight on this, it would be greatly appreciated. 

--Marwan



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: XLS files with no header

Posted by Marwan Gedeon <ma...@zaradoustra.com>.
I attached the file that is Excel 2.1, it seems it uses BIFF 2.0 format,
where no documentation about the format is available anywhere online. 
I just need to pull out the data in there, but first POI would complain
about the headers. Anyway to skip that part, and just extract the data,
would be awesome.

-----Original Message-----
From: Nick Burch [mailto:nick@torchbox.com] 
Sent: Tuesday, February 05, 2008 7:29 PM
To: POI Users List
Subject: RE: XLS files with no header

On Tue, 5 Feb 2008, Marwan Gedeon wrote:
> The file I'm unable to read is an excel 2.1 file, which is really old.

Wow, that is old

> But POI as I understand does not support this, any easy way to make it 
> support this format, since this format is still actively used by some 
> carriers for sending invoices to their customers?

Depends what you need to do with the file. Just get some simple numeric 
data out? Get formulas out? Get formatting out?

Many of the more complex records will certainly have changed, but you 
might be able to bodge something to work just with the numeric records. 
Try using the eventusermodel code (it's much simpler), and disable all the 
records in RecordFactory except NumberRecord. If that works, you'll have 
the cell numeric values, and you can add in other records as needed

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

RE: XLS files with no header

Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 5 Feb 2008, Marwan Gedeon wrote:
> The file I'm unable to read is an excel 2.1 file, which is really old.

Wow, that is old

> But POI as I understand does not support this, any easy way to make it 
> support this format, since this format is still actively used by some 
> carriers for sending invoices to their customers?

Depends what you need to do with the file. Just get some simple numeric 
data out? Get formulas out? Get formatting out?

Many of the more complex records will certainly have changed, but you 
might be able to bodge something to work just with the numeric records. 
Try using the eventusermodel code (it's much simpler), and disable all the 
records in RecordFactory except NumberRecord. If that works, you'll have 
the cell numeric values, and you can add in other records as needed

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: XLS files with no header

Posted by Marwan Gedeon <ma...@zaradoustra.com>.
The file I'm unable to read is an excel 2.1 file, which is really old. I
figured that out after removing the extension, opening it in excel, then
trying to save, and having Excel prompting if I want to save the 2.1 format
or not. 
But POI as I understand does not support this, any easy way to make it
support this format, since this format is still actively used by some
carriers for sending invoices to their customers?

-----Original Message-----
From: Nick Burch [mailto:nick@torchbox.com] 
Sent: Friday, February 01, 2008 3:42 PM
To: POI Users List
Subject: Re: XLS files with no header

On Thu, 31 Jan 2008, Marwan Gedeon wrote:
> I'm running through constraints in the format of an Excel file I have at
> hand, as it's being downloaded from a carrier directly.  My application
> needs to read the excel file as is without preopening in Excel, then
convert
> it to CSV. POI fails to open it with the error:
>
> java.io.IOException: Invalid header signature; read 4503629692403721,
> expected -2226271756974174256

This error means that your file isn't a valid OLE2 document

One thing you could try doing is saving the file, and looking at it. 
Perhaps it's not in excel format after all, but really something else?

If it is an excel file, but without the normal OLE2 wrapper (rare and odd, 
but not un-heard of) you'll need to wrap it up as OLE2 before passing to 
HSSF. Check the list archives for the appropriate few lines of POIFS code 
to call.

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XLS files with no header

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 31 Jan 2008, Marwan Gedeon wrote:
> I'm running through constraints in the format of an Excel file I have at
> hand, as it's being downloaded from a carrier directly.  My application
> needs to read the excel file as is without preopening in Excel, then convert
> it to CSV. POI fails to open it with the error:
>
> java.io.IOException: Invalid header signature; read 4503629692403721,
> expected -2226271756974174256

This error means that your file isn't a valid OLE2 document

One thing you could try doing is saving the file, and looking at it. 
Perhaps it's not in excel format after all, but really something else?

If it is an excel file, but without the normal OLE2 wrapper (rare and odd, 
but not un-heard of) you'll need to wrap it up as OLE2 before passing to 
HSSF. Check the list archives for the appropriate few lines of POIFS code 
to call.

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org