Bug 61543 - XSSFTable bug table remove after create
Summary: XSSFTable bug table remove after create
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-20 07:09 UTC by Edward
Modified: 2018-01-01 14:55 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edward 2017-09-20 07:09:02 UTC
I am facing a issue when try to remove a XSSF Table after creating one.
 
Here is my test case with manual print out result.
 
    Create 3 tables on a single sheet.
 
     [java] Create Table Name: /xl/tables/table1.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
     [java] Create Table Name: /xl/tables/table2.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
     [java] Create Table Name: /xl/tables/table3.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
 
Delete table2
 
    [java] Tables before deletion Name: /xl/tables/table1.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
     [java] Tables before deletion Name: /xl/tables/table2.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
     [java] Tables before deletion Name: /xl/tables/table3.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
 
     [java] Tables after deletion Name: /xl/tables/table1.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
     [java] Tables after deletion Name: /xl/tables/table3.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml
 
Create a new table table and it throws exception as below
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with the name '/xl/tables/table3.xml' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
 
Looks like it tries to re-use table3.xml which already exists.
 
When I look into the code, this line.
XSSFSheet line 3971
int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1;
Comment 1 Dominik Stadler 2017-09-28 12:55:47 UTC
Please state which exact version of POI you are using and please try to put your steps into a self-sufficient unit-test so we can actually try to reproduce the problem on our end.
Comment 2 Dominik Stadler 2017-12-30 15:52:14 UTC
Seems to be related to bug 57165 where we fixed this for sheets in workbooks. Probably a similar fix is necessary here to not always use "size()-1" as id for new table-parts
Comment 3 Dominik Stadler 2018-01-01 14:55:03 UTC
Should be fixed via r1819773.