- Code: Select all
WordprocessingMLPackage wordprocessingMLPackage = Docx4J.load(new File(System.getProperty("user.dir") + "/uploads/chartCopy.docx"));
Relationship rel = relationshipsPart.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);
Part part = relationshipsPart.getPart(rel);
System.out.println(part.getPartName().getName() );
wordprocessingMLPackage.getMainDocumentPart().addTargetPart(part, RelationshipsPart.AddPartBehaviour.RENAME_IF_NAME_EXISTS);
wordprocessingMLPackage.save(new File(System.getProperty("user.dir") + "/uploads/chartCopyNew.docx"));
However, it does not work either and here is the wrong info:
- Code: Select all
org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:346)
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:435)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:455)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:795)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:684)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:667)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:656)
at org.paipan.core.service.ChartCopySimpliy.main(ChartCopySimpliy.java:124)
Caused by: java.io.IOException: part '/word/charts/chart1.xml' not found
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:326)
... 11 more
20:51:08.940 [main] ERROR org.docx4j.openpackaging.io3.Save - Error marshalling JaxbXmlPart /word/charts/chart1.xml
org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:346)
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:435)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:455)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:795)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:684)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:667)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:656)
at org.paipan.core.service.ChartCopySimpliy.main(ChartCopySimpliy.java:124)
Caused by: java.io.IOException: part '/word/charts/chart1.xml' not found
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:326)
... 11 common frames omitted
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:403)
at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:795)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:684)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:667)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:656)
at org.paipan.core.service.ChartCopySimpliy.main(ChartCopySimpliy.java:124)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /word/document.xml
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:403)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:455)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
... 6 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Problem saving part /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:318)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:435)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
... 8 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:346)
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
... 10 more
Caused by: java.io.IOException: part '/word/charts/chart1.xml' not found
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:326)
... 11 more
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:403)
at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:795)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:684)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:667)
at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:656)
at org.paipan.core.service.ChartCopySimpliy.main(ChartCopySimpliy.java:124)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /word/document.xml
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:403)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:455)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
... 6 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Problem saving part /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:318)
at org.docx4j.openpackaging.io3.Save.savePart(Save.java:435)
at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:398)
... 8 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/charts/chart1.xml
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:346)
at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
... 10 more
Caused by: java.io.IOException: part '/word/charts/chart1.xml' not found
at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:326)
... 11 more
Is there a method to move chart to another document? Besides, is there a common method to move a part of word document?
looking forward for your reply!