I understand that hssf cannot deal with pivot tables itself,
but that it should be possible to read and write back workbooks
containing unknown (to hssf) records.
Here's what I get, when I read a simple xls file with one sheet
of data and a pivot table in another sheet:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:130)
at com.eekboom.pivot_test.Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at
org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
at
org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
... 14 more
Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException:
Unable to construct record instance, the following exception occured: null
at
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:237)
at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:130)
at com.eekboom.pivot_test.Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Process finished with exit code 1
I rather blindly modified the UnknownRecordConstructor and added a single line
of code,
restricting the size to valid values:
public UnknownRecord( short id, short size, byte[] data, int offset )
{
size = (short)Math.min(data.length - offset, size);
...
POI can read the file now, write it back and I can also still open it in excel.
Yet, it makes me wonder why POI gets the size calculation wrong.
Should I post the xls files here?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/