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);
}
错误: org.docx4j.openpackaging.exceptions.Docx4JException:找不到CustomXmlDataStoragePart!离开..
为什么找不到CustomXmlDataStoragePart?如何解决?
答案 0 :(得分:0)
CustomXmlDataStoragePartSelector旨在根据OpenDoPE规范使用内容控件处理文档:请参阅http://www.opendope.org
设置文档的最简单方法是使用其中一个Word AddIns,http://www.opendope.org/downloads/authoring-friendly/setup.exe或更旧版本{uglier http://www.opendope.org/downloads/authoring-advanced/setup.exe