找不到CustomXmlDataStoragePart!退出..错误使用docx4j将XML添加到Word

时间:2017-11-06 05:57:45

标签: java docx4j

    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!离开..

xml click here

为什么找不到CustomXmlDataStoragePart?如何解决?

1 个答案:

答案 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

进一步查看http://www.opendope.org/implementations.html