Created attachment 28922 [details] example test program When writing to a file using HSSFWorkbook.write() the write fails with the below stack trace, and wipes out any data existing in the file. This functionality was introduced in version 3.7b1, and has been confirmed to exist in the most recent production version as well (v3.8). I've attached a test program that reliably reproduces this. To use it unzip the attachment and review the README file. ----------------------- Exception in thread "main" java.lang.IllegalArgumentException: calculated end index (29228) is out of allowable range (29224..29226) at org.apache.poi.util.LittleEndianByteArrayOutputStream.<init>(LittleEndianByteArrayOutputStream.java:41) at org.apache.poi.hssf.record.StandardRecord.serialize(StandardRecord.java:38) at org.apache.poi.hssf.usermodel.HSSFWorkbook$SheetRecordCollector.serialize(HSSFWorkbook.java:1215) at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1261) at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1160) at poifseditor.PoifsEditor.addSomeRows(PoifsEditor.java:45) at poifseditor.PoifsEditor.main(PoifsEditor.java:62)
Can you narrow down which record is triggering the problem? Does the file pass the Microsoft Binary File Format Validator before being loaded in POI?
I don't have access to a Windows machine currently to run the Microsoft Binary File Format Validator. I've attached a copy of the excel file that is generated, so perhaps someone who is capable of running the validator can do so. I did not try to narrow down to which record is causing it because all of the records are identical -- they are all inserted by the "poifs-writer" module in the attached test harness.
Created attachment 28933 [details] sample source xls file. this sample file was generated by the poifs-writer module of the attached test program.
Just to make it clear: POI-3.6 (write) + POI-3.6 (edit) is success. POI-3.6 (write) + POI-3.7-beta1 (edit) fails. what is the result of using POI-3.8 (write) + POI-3.8 (edit) ? POI-3.6 (write) + POI-3.8 (edit) ? Yegor
POI-3.6 (write) + POI-3.6 (edit) is success. --> confirmed success POI-3.6 (write) + POI-3.7-beta1 (edit) fails. --> confirmed fails POI-3.8 (write) + POI-3.8 (edit) --> confirmed successful POI-3.6 (write) + POI-3.8 (edit) --> confirmed fails
FYI, using the attached test harness it's easy to swap versions by changing the version numbers in poifs-writer/pom.xml and poifs-editor/pom.xml and then running 'mvn -U clean package' before running 'runTest.sh'
I don't see a bug here. POI-3.6 is more than 2 years old and many bugs have been fixed since then. can you try a simple workaround: if poifs-writer fails with IllegalArgumentException which indicates that the file was created by a old version of POI then write it to a byte array and read back. Something like this: wb = new HSSFWorkbook("created by POI-3.6.xls"); try { // do stuff } catch (IllegalArgumentException e){ ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); wb = new HSSFWorkbook(new ByteArrayOutputStream(out.toByteArray())); // do stuff } Let us know if it worked for you. Cheers, Yegor
i've been able to address the issue with what you describe (n.b.: with a fix for the typo to use ByteArrayInputStream as an argument to the HSSFWorksheet ctor). is there a more reliable way to determine the version other than by exception handling? e.g. is there a metadata property somewhere that would reflect this? i've toyed with the idea of using getImplementationVersion() (as the test program uses for printing)... all this said, i'm surprised by the reluctance to try to address this issue. as it happens we have several thousand legacy spreadsheets in pre-3.6 format. can you be more specific why it won't be fixed?
(In reply to comment #8) > i've been able to address the issue with what you describe (n.b.: with a fix > for the typo to use ByteArrayInputStream as an argument to the HSSFWorksheet > ctor). > > is there a more reliable way to determine the version other than by > exception handling? e.g. is there a metadata property somewhere that would > reflect this? > No, HSSF does not write version info in the output. > i've toyed with the idea of using getImplementationVersion() (as the test > program uses for printing)... > > all this said, i'm surprised by the reluctance to try to address this issue. > as it happens we have several thousand legacy spreadsheets in pre-3.6 > format. can you be more specific why it won't be fixed? It wasn't clear that you have several thousand legacy spreadsheets in pre-3.6 format. I thought tha tall you need is to upgrade both writer and editor parts to the latest and greatest POI-3.8. I re-opened the bug. Hope to have it fixed by POI-3.9 (late 2012). Yegor
Is this still expected to be released in late 2012? If so, what's the target milestone for it? Thanks
This bug is open which means we plan to address it in the future. POI is a volunteer project. If this bug is important for you, please do work on it and submit a patch. Otherwise please wait. We plan to release POI-3.9 in late 2012, hope this problem will be fixed by then. Yegor (In reply to comment #10) > Is this still expected to be released in late 2012? If so, what's the > target milestone for it? Thanks
Should be fixed in r1402186. Please try with the latest build from trunk. Yegor
Thanks much. Will this be going out with the next release? Or will it need to be scheduled?
Yes, the fix will be included in POI-3.9. I plan to roll it some time Dec 2012. (In reply to comment #13) > Thanks much. Will this be going out with the next release? Or will it need > to be scheduled?