Bug 52836

Summary: Cannot create a new XSSFDrawing object
Product: POI Reporter: Jimmy <jchakkalakal>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: martin.studer
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Code for reproduce the problem mentioned above
Template used by me for the code
Another sample file which leads to the same exception
Potential patch for first error message

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