You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Eric B." <eb...@hotmail.com> on 2011/07/07 18:27:05 UTC

Anyway to ignore LeftoverDataException?

Hi,

I'm using POI 3.7 and trying to read an Excel file.  Upon instantiating 
an HSSFWorkbook I get the following error:

HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: 
Initialisation of record 0xDA left 2 bytes remaining still to be read.
	at 
org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
	at 
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:216)
	at 
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:442)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:263)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:188)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
...


I have tried to open the excel file in Excel and OpenOffice, and both 
open the file without failure.  If I resave the file from either Excel 
or OO, then I am able to read it without difficulty.

Is this a POI error, or a file structure error?  If the later, is there 
any way to tell POI to ignore a LeftOverDataException?

Thanks,

Eric


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


Re: Anyway to ignore LeftoverDataException?

Posted by Dave Fisher <da...@comcast.net>.
On Jul 7, 2011, at 2:25 PM, Eric B. wrote:

> On 07/07/2011 03:54 PM, Dave Fisher wrote:
> 
>>> 
>>> Any suggestions as to how I can "repair" an xls file such that poi will understand it?
>> 
>> The first step is to identify where the problem is in the file.
>> 
>> Take two files. One is the bad file, and two is the bad file after it is fixed by re-saving in Excel.
>> 
>> Try the BiffViewer[1] on both and see how the dump differs. Report back with the differences and someone will help.
>> 
> 
> Thanks for the tip.  Any preferences as to the options that I should be using in BiffViewer to create the dumps?

Use the smallest file that shows the problem. As far as options I am not sure, experiment.

Regards,
Dave


> 
> Thanks,
> 
> Eric
> 
> 
> ---------------------------------------------------------------------
> 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: Anyway to ignore LeftoverDataException?

Posted by "Eric B." <eb...@hotmail.com>.
On 07/07/2011 03:54 PM, Dave Fisher wrote:

>>
>> Any suggestions as to how I can "repair" an xls file such that poi will understand it?
>
> The first step is to identify where the problem is in the file.
>
> Take two files. One is the bad file, and two is the bad file after it is fixed by re-saving in Excel.
>
> Try the BiffViewer[1] on both and see how the dump differs. Report back with the differences and someone will help.
>

Thanks for the tip.  Any preferences as to the options that I should be 
using in BiffViewer to create the dumps?

Thanks,

Eric


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


Re: Anyway to ignore LeftoverDataException?

Posted by "Eric B." <eb...@hotmail.com>.
On 07/07/2011 03:54 PM, Dave Fisher wrote:
>
>
> The first step is to identify where the problem is in the file.
>
> Take two files. One is the bad file, and two is the bad file after it is fixed by re-saving in Excel.
>
> Try the BiffViewer[1] on both and see how the dump differs. Report back with the differences and someone will help.
>

Thanks for the tip.  I tried BiffViewer, and the problem is that both 
files differ significantly.  (Bad file is 9.5K, Good file is 14K).  I 
generated the bad file with only 1 row to minimize the number of cells 
and records generated.

Bad file has 149 records.  Good file has 151 records.

The biggest problem is that some records are signficantly different. 
Some just have different record numbers,   I don't know if it is 
important to list all the differences/changes, or just to list the 
problem record.

In the bad file, Record 54 is problematic.  I'm listing both files in 
case someone knows or can pinpoint what the issue might be.:

Bad File:
Offset=0x000003C4(964) recno=53 sid=0x0085 size=0x000E(14)
[BOUNDSHEET]
     .bof        = 0x000006E9
     .options    = 0x0000
     .unicodeflag= 0x00
     .sheetname  = Sheet2
[/BOUNDSHEET]

[BOOKBOOL]
     .savelinkvalues  = 7
[/BOOKBOOL]

Offset=0x000003D6(982) recno=54 sid=0x00DA size=0x0004(4)
Offset=0x000003DE(990) recno=55 sid=0x00FC size=0x00D3(211)
[SST]
     .numstrings     = f
     .uniquestrings  = f
     .string_0      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Category
[/UNICODESTRING]

     .string_1      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Instance
[/UNICODESTRING]

     .string_2      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 0
     .string          = Token
[/UNICODESTRING]

     .string_3      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 0
     .string          = Flags
[/UNICODESTRING]

     .string_4      = [UNICODESTRING]
     .charcount       = 4
     .optionflags     = 0
     .string          = Text
[/UNICODESTRING]

     .string_5      = [UNICODESTRING]
     .charcount       = b
     .optionflags     = 0
     .string          = Description
[/UNICODESTRING]

     .string_6      = [UNICODESTRING]
     .charcount       = a
     .optionflags     = 0
     .string          = Translated
[/UNICODESTRING]

     .string_7      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Modified
[/UNICODESTRING]

     .string_8      = [UNICODESTRING]
     .charcount       = 7
     .optionflags     = 0
     .string          = Details
[/UNICODESTRING]

     .string_9      = [UNICODESTRING]
     .charcount       = 4
     .optionflags     = 1
     .string          = Date
[/UNICODESTRING]

     .string_10      = [UNICODESTRING]
     .charcount       = 13
     .optionflags     = 1
     .string          = 2011-07-07 13:41:02
[/UNICODESTRING]

     .string_11      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 1
     .string          = Username
[/UNICODESTRING]

     .string_12      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 1
     .string          = admin
[/UNICODESTRING]

     .string_13      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 1
     .string          = Language
[/UNICODESTRING]

     .string_14      = [UNICODESTRING]
     .charcount       = 2
     .optionflags     = 1
     .string          = en
[/UNICODESTRING]

[/SST]

Offset=0x000004B5(1205) recno=56 sid=0x000A size=0x0000(0)
[EOF]
[/EOF]





Good File:
Offset=0x00000538(1336) recno=59 sid=0x0085 size=0x000E(14)
[BOUNDSHEET]
     .bof        = 0x0000085D
     .options    = 0x0000
     .unicodeflag= 0x00
     .sheetname  = Sheet2
[/BOUNDSHEET]

Offset=0x0000054A(1354) recno=60 sid=0x008C size=0x0004(4)
[COUNTRY]
     .defaultcountry  = 1
     .currentcountry  = 1
[/COUNTRY]

Offset=0x00000552(1362) recno=61 sid=0x01C1 size=0x0008(8)
[RECALCID]
     .reserved = 0x0000
     .engineId = 0x00013880
[/RECALCID]

Offset=0x0000055E(1374) recno=62 sid=0x00FC size=0x00A5(165)
[SST]
     .numstrings     = f
     .uniquestrings  = f
     .string_0      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Category
[/UNICODESTRING]

     .string_1      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Instance
[/UNICODESTRING]

     .string_2      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 0
     .string          = Token
[/UNICODESTRING]

     .string_3      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 0
     .string          = Flags
[/UNICODESTRING]

     .string_4      = [UNICODESTRING]
     .charcount       = 4
     .optionflags     = 0
     .string          = Text
[/UNICODESTRING]

     .string_5      = [UNICODESTRING]
     .charcount       = b
     .optionflags     = 0
     .string          = Description
[/UNICODESTRING]

     .string_6      = [UNICODESTRING]
     .charcount       = a
     .optionflags     = 0
     .string          = Translated
[/UNICODESTRING]

     .string_7      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Modified
[/UNICODESTRING]

     .string_8      = [UNICODESTRING]
     .charcount       = 7
     .optionflags     = 0
     .string          = Details
[/UNICODESTRING]

     .string_9      = [UNICODESTRING]
     .charcount       = 4
     .optionflags     = 0
     .string          = Date
[/UNICODESTRING]

     .string_10      = [UNICODESTRING]
     .charcount       = 13
     .optionflags     = 0
     .string          = 2011-07-07 13:41:02
[/UNICODESTRING]

     .string_11      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Username
[/UNICODESTRING]

     .string_12      = [UNICODESTRING]
     .charcount       = 5
     .optionflags     = 0
     .string          = admin
[/UNICODESTRING]

     .string_13      = [UNICODESTRING]
     .charcount       = 8
     .optionflags     = 0
     .string          = Language
[/UNICODESTRING]

     .string_14      = [UNICODESTRING]
     .charcount       = 2
     .optionflags     = 0
     .string          = en
[/UNICODESTRING]

[/SST]

Offset=0x00000607(1543) recno=63 sid=0x00FF size=0x0012(18)
[EXTSST]
     .dsst           = 8
     .numInfoRecords = 2
     .inforecord     = 0
     .streampos      = 56a
     .sstoffset      = c
     .inforecord     = 1
     .streampos      = 5bd
     .sstoffset      = 5f
[/EXTSST]

Offset=0x0000061D(1565) recno=64 sid=0x0863 size=0x0015(21)
[BOOKEXT] (0x863)
   rawData=[63, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 15, 00, 00, 
00, 00, 00, 00, 00, 02]
[/BOOKEXT]

Offset=0x00000636(1590) recno=65 sid=0x000A size=0x0000(0)
[EOF]
[/EOF]



Thanks!

Eric


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


Re: Anyway to ignore LeftoverDataException?

Posted by Dave Fisher <da...@comcast.net>.
On Jul 7, 2011, at 12:42 PM, Eric B. wrote:

> On 07/07/2011 02:14 PM, Eric B. wrote:
>> On 07/07/2011 01:56 PM, Nick Burch wrote:
>>> On Thu, 7 Jul 2011, Eric B. wrote:
>>>> Is this a POI error, or a file structure error? If the later, is there
>>>> any way to tell POI to ignore a LeftOverDataException?
>>> 
>>> This error is telling you that an assumption POI has made about the
>>> structure of one of the records has turned out incorrect
>>> 
>>> The fix is to look at the excel file format specs, and compare the POI
>>> record code and the file to them. If POI is wrong, POI needs fixing.
>>> (This will typically happen when we don't check for an extension flag or
>>> similar). If the file isn't spec compliant, then we need to decide if
>>> it's salvagable or not, and put in a workaround if possible
>> 
>> 
>> I am nearly certain that the file being generated is not to spec. My
>> problem is that I do not have the ability to change the tool generating
>> the Excel file, and consequently am stuck with this file format.
>> 
>> Is there anything in POI that would let me silently ignore these errors,
>> or do I need to hack POI to get this to work? ie: I can use Spring AOP
>> or AspectJ to intercept a thrown error and silently ignore it, but I
>> consider that to be quite an ugly solution.
> 
> In retrospect, my concept of using Spring or AspectJ to simply ignore the error does not work given that the pointer does not know the correct start of the next record and fails miserably.
> 
> Any suggestions as to how I can "repair" an xls file such that poi will understand it?

The first step is to identify where the problem is in the file.

Take two files. One is the bad file, and two is the bad file after it is fixed by re-saving in Excel.

Try the BiffViewer[1] on both and see how the dump differs. Report back with the differences and someone will help.

Regards,
Dave

[1] http://poi.apache.org/apidocs/org/apache/poi/hssf/dev/BiffViewer.html

> 
> Thanks,
> 
> Eric
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Anyway to ignore LeftoverDataException?

Posted by "Eric B." <eb...@hotmail.com>.
On 07/07/2011 02:14 PM, Eric B. wrote:
> On 07/07/2011 01:56 PM, Nick Burch wrote:
>> On Thu, 7 Jul 2011, Eric B. wrote:
>>> Is this a POI error, or a file structure error? If the later, is there
>>> any way to tell POI to ignore a LeftOverDataException?
>>
>> This error is telling you that an assumption POI has made about the
>> structure of one of the records has turned out incorrect
>>
>> The fix is to look at the excel file format specs, and compare the POI
>> record code and the file to them. If POI is wrong, POI needs fixing.
>> (This will typically happen when we don't check for an extension flag or
>> similar). If the file isn't spec compliant, then we need to decide if
>> it's salvagable or not, and put in a workaround if possible
>
>
> I am nearly certain that the file being generated is not to spec. My
> problem is that I do not have the ability to change the tool generating
> the Excel file, and consequently am stuck with this file format.
>
> Is there anything in POI that would let me silently ignore these errors,
> or do I need to hack POI to get this to work? ie: I can use Spring AOP
> or AspectJ to intercept a thrown error and silently ignore it, but I
> consider that to be quite an ugly solution.

In retrospect, my concept of using Spring or AspectJ to simply ignore 
the error does not work given that the pointer does not know the correct 
start of the next record and fails miserably.

Any suggestions as to how I can "repair" an xls file such that poi will 
understand it?

Thanks,

Eric



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


Re: Anyway to ignore LeftoverDataException?

Posted by "Eric B." <eb...@hotmail.com>.
On 07/07/2011 01:56 PM, Nick Burch wrote:
> On Thu, 7 Jul 2011, Eric B. wrote:
>> Is this a POI error, or a file structure error? If the later, is there
>> any way to tell POI to ignore a LeftOverDataException?
>
> This error is telling you that an assumption POI has made about the
> structure of one of the records has turned out incorrect
>
> The fix is to look at the excel file format specs, and compare the POI
> record code and the file to them. If POI is wrong, POI needs fixing.
> (This will typically happen when we don't check for an extension flag or
> similar). If the file isn't spec compliant, then we need to decide if
> it's salvagable or not, and put in a workaround if possible


I am nearly certain that the file being generated is not to spec.  My 
problem is that I do not have the ability to change the tool generating 
the Excel file, and consequently am stuck with this file format.

Is there anything in POI that would let me silently ignore these errors, 
or do I need to hack POI to get this to work?  ie: I can use Spring AOP 
or AspectJ to intercept a thrown error and silently ignore it, but I 
consider that to be quite an ugly solution.

Thanks,

Eric



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


Re: Anyway to ignore LeftoverDataException?

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 7 Jul 2011, Eric B. wrote:
> Is this a POI error, or a file structure error?  If the later, is there 
> any way to tell POI to ignore a LeftOverDataException?

This error is telling you that an assumption POI has made about the 
structure of one of the records has turned out incorrect

The fix is to look at the excel file format specs, and compare the POI 
record code and the file to them. If POI is wrong, POI needs fixing. (This 
will typically happen when we don't check for an extension flag or 
similar). If the file isn't spec compliant, then we need to decide if it's 
salvagable or not, and put in a workaround if possible

Nick

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


RE: Anyway to ignore LeftoverDataException?

Posted by Matt Rogghe <mr...@blazent.com>.
I've seen behavior exactly like you are talking about with old Excel formats and Excel files written by some 3rd party reporting tools.  Apparently the pre-2007 (non-OOXML) Excel file specification was never quite standardized.  My solution to date has been to discard those files and ask for Excel 2007+ formats for which I haven't seen strange errors like the below.  I'd be interested as well to know if anyone has an alternate solution.

-----Original Message-----
From: Eric B. [mailto:ebenze@hotmail.com] 
Sent: Thursday, July 07, 2011 12:27 PM
To: user@poi.apache.org
Subject: Anyway to ignore LeftoverDataException?

Hi,

I'm using POI 3.7 and trying to read an Excel file.  Upon instantiating 
an HSSFWorkbook I get the following error:

HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: 
Initialisation of record 0xDA left 2 bytes remaining still to be read.
	at 
org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
	at 
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:216)
	at 
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:442)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:263)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:188)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
...


I have tried to open the excel file in Excel and OpenOffice, and both 
open the file without failure.  If I resave the file from either Excel 
or OO, then I am able to read it without difficulty.

Is this a POI error, or a file structure error?  If the later, is there 
any way to tell POI to ignore a LeftOverDataException?

Thanks,

Eric


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