You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Brian Callaghan <ca...@yahoo.com> on 2012/10/10 22:56:32 UTC

Handling unexpected CRN sequence

Let's start from the beginning, I'm getting the following exception when reading a 97-2003 Excel worksheet.
 
java.lang.ClassCastException: 
  org.apache.poi.hssf.record.CRNCountRecord cannot be cast to org.apache.poi.hssf.record.CRNRecord
org.apache.poi.hssf.model.LinkTable$CRNBlock.<init>(LinkTable.java:82)
org.apache.poi.hssf.model.LinkTable$ExternalBookBlock.<init>(LinkTable.java:108)
org.apache.poi.hssf.model.LinkTable.<init>(LinkTable.java:187)
org.apache.poi.hssf.model.InternalWorkbook.createWorkbook(InternalWorkbook.java:276)
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:287)
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248)
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192)
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327)
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308)
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:70)

When I dump the content of the file using the biff viewer, I see the following sequence
 
Offset=0x00009EDC(40668) recno=731 sid=0x0059 size=0x0004(4)
[UNKNOWNRECORD] (0x59)
  rawData=[06, 00, 04, 00]
[/UNKNOWNRECORD]

Offset=0x00009EE4(40676) recno=732 sid=0x005A size=0x000D(13)
[UNKNOWNRECORD] (0x5A)
  rawData=[00, 00, 25, 00, 01, 14, AE, 47, E1, 7A, 14, EE, 3F]
[/UNKNOWNRECORD]

Offset=0x00009EF5(40693) recno=733 sid=0x0059 size=0x0004(4)
[UNKNOWNRECORD] (0x59)
  rawData=[00, 00, 05, 00]
[/UNKNOWNRECORD]

Unless I'm missing something but looking at the LinkTable code, it appears that we should have seen 6 CRN records when in fact, there's only one so the second CRN Count Record is causing the class cast exception.
 
I don't know enough about the content of the CRN records to know if the 5 additional records are just simply missing or the actual parsing of the first CRN record would have told you not to expect the next 5.
 
I can tell you, whether I load this file from Excel or other compatible viewers, none of them complain about this sequence so either they're handling/ignoring it or it's not really an issue (ie. bug in LinkTable).
 
How can I proceed?  
 
The file in question is published by a financial institution so it's treated like a black box with no ability to change their end.