Bug 52836 - Cannot create a new XSSFDrawing object
Summary: Cannot create a new XSSFDrawing object
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-06 13:30 UTC by Jimmy
Modified: 2016-10-18 01:34 UTC (History)
1 user (show)



Attachments
Code for reproduce the problem mentioned above (734 bytes, application/octet-stream)
2012-03-06 13:30 UTC, Jimmy
Details
Template used by me for the code (53.92 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2012-05-22 13:16 UTC, Jimmy
Details
Another sample file which leads to the same exception (14.60 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2015-12-29 15:24 UTC, Martin Studer
Details
Potential patch for first error message (1.82 KB, patch)
2016-02-14 21:12 UTC, Dominik Stadler
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jimmy 2012-03-06 13:30:07 UTC
Created attachment 28424 [details]
Code for reproduce the problem mentioned above

Hallo,

I am not able to create a XSSFDrawing-Object. Each time I try to create one, I receive following error:

Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidOperationException: A part with the name '/xl/drawings/drawing2.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]
	at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:260)
	at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:233)
	at org.apache.poi.xssf.usermodel.XSSFSheet.createDrawingPatriarch(XSSFSheet.java:402)
	at ExcelFileCreationWithPOI.main(ExcelFileCreationWithPOI.java:28)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidOperationException: A part with the name '/xl/drawings/drawing2.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]
	at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:700)
	at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:664)
	at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:252)
	... 3 more

Hereby I attach the code, which I have used.

Please do notify me as soon as a solution is found.

Thanks im advance!

Regards

Jimmy
Comment 1 Yegor Kozlov 2012-03-13 07:16:11 UTC
Please attach the template that is used by your code snippet. 

Yegor
Comment 2 Jimmy 2012-05-22 13:16:38 UTC
Created attachment 28816 [details]
Template used by me for the code
Comment 3 Jimmy 2012-05-22 13:17:53 UTC
Hallo Yegor,

I am attached the template, that I have used in the code

Kind regards

Jimmy Chakkalakal
Comment 4 Dominik Stadler 2015-09-03 19:15:50 UTC
Works for me with current trunk (3.13-beta1 + some more changes), so it seems to have been fixed at some point.
Comment 5 Dominik Stadler 2015-09-03 19:19:09 UTC
sorry, I was wrong, it still happens when I use the correct sample file.
Comment 6 Dominik Stadler 2015-09-29 13:44:16 UTC
The file seems to have some unused/leftover content in the internal XML/ZIP, there is a xl/drawings/drawing2.xml which is not used. If you open the file in Excel/LibreOffice and re-save it, POI can work with it as expected...
Comment 7 Martin Studer 2015-12-29 15:22:52 UTC
Attached is another sample file which leads to the same exception
Comment 8 Martin Studer 2015-12-29 15:24:00 UTC
Created attachment 33383 [details]
Another sample file which leads to the same exception
Comment 9 Dominik Stadler 2016-02-14 21:12:21 UTC
Created attachment 33553 [details]
Potential patch for first error message

I tried to have a go at this via the attached patch. If I simply try to avoid the error by forcefully removing the invalid part before creating the new one, creating a new sheet works, however when I try to clone the sheet, I get a different error: 

org.apache.poi.POIXMLException: org.apache.xmlbeans.XmlException: Element chartsheet@http://schemas.openxmlformats.org/spreadsheetml/2006/main is not a valid worksheet@http://schemas.openxmlformats.org/spreadsheetml/2006/main document or a valid substitution.
	at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:174)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.cloneSheet(XSSFWorkbook.java:582)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.cloneSheet(XSSFWorkbook.java:1)
	at org.apache.poi.xssf.usermodel.TestXSSFBugs.test52836(TestXSSFBugs.java:2977)
Caused by: org.apache.xmlbeans.XmlException: Element chartsheet@http://schemas.openxmlformats.org/spreadsheetml/2006/main is not a valid worksheet@http://schemas.openxmlformats.org/spreadsheetml/2006/main document or a valid substitution.
	at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:329)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1280)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1264)
	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
	at org.apache.poi.POIXMLTypeLoader.parse(POIXMLTypeLoader.java:92)
	at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
	at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:172)
	... 26 more
Comment 10 Zero 2016-10-18 01:34:46 UTC
*** Bug 60255 has been marked as a duplicate of this bug. ***
Fixed in 3.16-beta1