Bug 56886

Summary: Unreadable content when inserting a column into an Excel Table
Product: POI Reporter: Javen O'Neal <onealj>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: zip file containing excel files used to reproduce the bugs, table1.xml and diffs

Description Javen O'Neal 2014-08-26 02:29:38 UTC
Created attachment 31941 [details]
zip file containing excel files used to reproduce the bugs, table1.xml and diffs

Steps to reproduce:
In Excel:
1. add data to a sheet in a blank workbook
2. Select the range and make it a table (Excel > Insert > Tables > Table)
3. Insert a new column in the middle of the table.
4. Save the workbook as OOXML format

In POI:
5. Open, save, and close the workbook:
    String input_filename = "Excel_does_not_find_unreadable_content.xlsx";
    String output_filename = "Excel_finds_unreadable_content.xlsx";
    Workbook wb = WorkbookFactory.create(FileInputStream(input_filename));
    wb.write(FileOutputStream(File(output_filename)));

In Excel:
6. Open workbook. Excel dialog: "Excel found unreadable content in <filename.xlsx>. Do you want to recover the contents of this workbook. If you trust the source of this workbook, click Yes."
Comment 1 Javen O'Neal 2014-08-26 02:33:08 UTC
It appears that updateHeaders, which is called when the table is written out via writeTo(OutputStream), incorrectly updates the tableColumn names.
This occurs because the order of the columns (column index relative to the first column) is not necessarily the same as the tableColumn.id.

--- "a/Q:\\ABDT\\s1d1\\c band tables\\bug\\table1 (table column inserted after table was created - before POI).xml"	
+++ "b/Q:\\ABDT\\s1d1\\c band tables\\bug\\table1 (table column inserted after table was created - after POI).xml"
     <tableColumns count="4">
         <tableColumn id="1" name="City"/>
-        <tableColumn id="4" name="Population"/>
-        <tableColumn id="2" name="Latitude"/>
-        <tableColumn id="3" name="Longitude"/>
+        <tableColumn id="4" name="Longitude"/>
+        <tableColumn id="2" name="Population"/>
+        <tableColumn id="3" name="Latitude"/>
     </tableColumns>
Comment 2 Dominik Stadler 2015-03-03 19:58:31 UTC
I tried this with latest 3.12-beta1 and could not reproduce it. Can you check if this was in fact fixed since 3.10 was released?
Comment 3 Javen O'Neal 2015-03-06 19:44:19 UTC
I was unable to reproduce this bug in POI 3.11-final and 3.12-beta1, so it's safe to assume that some change made between 3.10-final and 3.11-final resolved this issue.

Commits that may have resolved this problem
* r1596624 bug 56274 Correct SXSSF writing of tables when creating from a template
* r1564050 bug 55923 Xml data export leads to a NPE when sorting output data
* bug56814 Switch from dom4j to JAXP
* update Apache XMLBeans to 2.6.0
* r1621209 bug 26730 Fix exporting XML if schema contains ref-elements

This bug can be closed.
Comment 4 Dominik Stadler 2015-03-08 19:47:08 UTC
Ok, thanks for testing, I am closing this issue as resolved based on test-results reported in the previous comment.