I use the following code to insert a macro script into my docm document
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) ...