Bug 61281 - XML export of xlsx results in IndexOutOfBoundsException
Summary: XML export of xlsx results in IndexOutOfBoundsException
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.14-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-11 11:17 UTC by Daniel
Modified: 2017-07-12 10:54 UTC (History)
1 user (show)



Attachments
[PATCH] proposed patch including testcase (8.27 KB, text/plain)
2017-07-11 11:21 UTC, Daniel
Details
xlsx which ends up in a IndexOutOfBoundsException (9.68 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2017-07-11 12:18 UTC, Daniel
Details
Proposed fix that provides same behaviour as excel (8.73 KB, patch)
2017-07-12 09:21 UTC, Daniel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel 2017-07-11 11:17:11 UTC
When attempting to Export the XML of attached xlsx, there occurs following exception:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
	at java.util.ArrayList.rangeCheck(Unknown Source)
	at java.util.ArrayList.get(Unknown Source)
	at org.apache.poi.xssf.extractor.XSSFExportToXml.exportToXML(XSSFExportToXml.java:203)
	at org.apache.poi.xssf.extractor.XSSFExportToXml.exportToXML(XSSFExportToXml.java:109)

The reason is, that one column of the table isn't mapped. When I do the export from Excel, it works. There is a different handling between Excel and Apache POI.
The code for exporting the XML is as following:

 XSSFWorkbook wb = /*given from previous code execution*/;
       for (XSSFMap map : wb.getCustomXMLMappings()) {
           XSSFExportToXml exporter = new XSSFExportToXml(map);

           ByteArrayOutputStream os = new ByteArrayOutputStream();
           exporter.exportToXML(os, true);
       }
Comment 1 Daniel 2017-07-11 11:21:52 UTC
Created attachment 35119 [details]
[PATCH] proposed patch including testcase
Comment 2 Daniel 2017-07-11 11:58:45 UTC
Comment on attachment 35119 [details]
[PATCH] proposed patch including testcase

Mark patch as obsolete, as the solution is not complete
Comment 3 Daniel 2017-07-11 12:18:17 UTC
Created attachment 35120 [details]
xlsx which ends up in a IndexOutOfBoundsException
Comment 4 PJ Fanning 2017-07-11 16:39:32 UTC
added guard in https://svn.apache.org/viewvc?view=revision&revision=1801634
Comment 5 Daniel 2017-07-12 09:20:42 UTC
Thanks for your fast fix. unfortunately, it just gets rid of the exception, but doesn't provide the same behaviour as the export in Excel does. ==> Reopen

Please see attached patch that has a testcase illustrating the Problem and a proposed fix.
Comment 6 Daniel 2017-07-12 09:21:55 UTC
Created attachment 35122 [details]
Proposed fix that provides same behaviour as excel
Comment 7 PJ Fanning 2017-07-12 10:09:22 UTC
Hi Daniel - any chance you could do a Github Pull Request? https://github.com/apache/poi
Comment 8 PJ Fanning 2017-07-12 10:54:37 UTC
Latest patch applied using https://svn.apache.org/viewvc?view=revision&revision=1801721