Reputation: 31
public void xmlToWordExport() throws Exception {
String input_DOCX = "D:/Temp/data_template/template.docx";
String input_XML = "D:/eclipse/jaxb.xml";
String OUTPUT_DOCX = "D:/eclipse-workspace/PWCRAR/OUT_ContentControlsMergeXML.docx";
WordprocessingMLPackage wordMLPackage = Docx4J.load(new File(input_DOCX));
CustomXmlDataStoragePart customXmlDataStoragePart
= CustomXmlDataStoragePartSelector.getCustomXmlDataStoragePart(wordMLPackage);
if (customXmlDataStoragePart==null) {
System.out.println("Couldn't find CustomXmlDataStoragePart! exiting..");
return;
}
System.out.println("Getting " + input_XML);
FileInputStream xmlStream = new FileInputStream(new File(input_XML));
Docx4J.bind(wordMLPackage, xmlStream, Docx4J.FLAG_BIND_INSERT_XML | Docx4J.FLAG_BIND_BIND_XML | Docx4J.FLAG_BIND_REMOVE_SDT);
//Save the document
Docx4J.save(wordMLPackage, new File(OUTPUT_DOCX), Docx4J.FLAG_NONE);
System.out.println("Saved: " + OUTPUT_DOCX);
}
error: org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't find CustomXmlDataStoragePart! exiting..
Why couldn't find CustomXmlDataStoragePart? How to fix it?
Upvotes: 1
Views: 1044
Reputation: 15863
CustomXmlDataStoragePartSelector is intended to work with documents using content controls according to the OpenDoPE spec: see http://www.opendope.org
The easiest way to set up your document is to use one of the Word AddIns, either http://www.opendope.org/downloads/authoring-friendly/setup.exe or the older/uglier http://www.opendope.org/downloads/authoring-advanced/setup.exe
See further http://www.opendope.org/implementations.html
Upvotes: 2