Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 变量没有被替换_Java_Docx_Docx4j - Fatal编程技术网

Java 变量没有被替换

Java 变量没有被替换,java,docx,docx4j,Java,Docx,Docx4j,我编写了一些代码来替换docx tamplate文件头中的变量 List<SectionWrapper> sectionWrappers = this.wordMLPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); HeaderPart defa

我编写了一些代码来替换docx tamplate文件头中的变量

List<SectionWrapper> sectionWrappers = this.wordMLPackage.getDocumentModel().getSections();
for (SectionWrapper sw : sectionWrappers) {
    HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
    HeaderPart defaultHP = hfp.getDefaultHeader();
        if (defaultHP != null) {
            defaultHP.variableReplace(getVariablesForChange());
            if (hfp.getFirstHeader() != null) {
              hfp.getFirstHeader().variableReplace(getVariablesForChange());
            }
        }
}
List sectionWrappers=this.wordMLPackage.getDocumentModel().getSections();
用于(sectionWrappers sw:sectionWrappers){
HeaderFooterPolicy hfp=sw.getHeaderFooterPolicy();
HeaderPart defaultHP=hfp.getDefaultHeader();
如果(默认HP!=null){
defaultHP.variableReplace(getVariablesForChange());
if(hfp.getFirstHeader()!=null){
hfp.getFirstHeader().variableReplace(getVariablesForChange());
}
}
}
getVariablesForChange()
是一个包含变量和值的映射。 当我运行单元测试时,替换是非常好的,但是我在我的web应用程序中使用它,变量没有被替换。 例如,变量是:
${TOCHANGE}
它在更改TOCHANGE后看起来是这样的

Docx4j版本为:3.3.6


请帮助我解决此问题。

如果您的密钥在docx中被拆分为多个单独的运行,则此问题将无法解决


请给我更多的信息,好吗?我不明白为什么在单元测试中使用相同的过程。我应该怎么做才能在Tomee Plumum上实现这一点?将document.xml内容发布到问题中,或者将整个docx文件发布到某个地方,以便我可以看到它。您可以在此处下载:header1.xml:和document.xml: