In docx4j version 8.2.0, the code below is work for me.
In docx4j version 8.3.0, the code below is not working anymore.
- Code: Select all
public void embed(WordprocessingMLPackage mlPackage) {
InputStream is = new ClassPathResource("/vbaProject.bin").getInputStream();
VbaProjectBinaryPart vbaProject = new VbaProjectBinaryPart();
vbaProject.setBinaryData(is);
mlPackage.getMainDocumentPart().addTargetPart(vbaProject);
InputStream is2 = new ClassPathResource("/vbaData.xml").getInputStream();
VbaDataPart vbaData = new VbaDataPart();
vbaData.unmarshal(is2);
vbaProject.addTargetPart(vbaData);
mlPackage.getContentTypeManager().addDefaultContentType("bin", "application/vnd.ms-office.vbaProject");
mlPackage.getContentTypeManager().removeOverrideContentType(vbaProject.getPartName());
}
When I run save(file) function, it returns me the error message like this:
- Code: Select all
718d00> org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/vbaData.xml
718d00> at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:392)
718d00> at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
718d00> at org.docx4j.openpackaging.io3.Save.savePart(Save.java:436)
718d00> at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:399)
718d00> at org.docx4j.openpackaging.io3.Save.savePart(Save.java:456)
718d00> at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:399)
718d00> at org.docx4j.openpackaging.io3.Save.savePart(Save.java:456)
718d00> at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:399)
718d00> at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
718d00> at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:788)
718d00> at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:684)
718d00> at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:667)
718d00> at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:656)