DocX4J - replace variable (groovy) -
i trying replace variable in docx file.
i have following code written in groovy:
def replaceworddocxcontent() { docxfile = this.docxfile string outputfilepath = docxfile.replace('.docx', '_output.docx') wordprocessingmlpackage wordmlpackage = wordprocessingmlpackage.load(new java.io.file(docxfile)); list<map<datafieldname, string>> data = new arraylist<map<datafieldname, string>>(); map<datafieldname, string> item = new hashmap<datafieldname, string>(); item.put(new datafieldname("evidsrv"), "abcdefghij"); data.add(item); org.docx4j.model.fields.merge.mailmerger.setmergefieldinoutput(outputfield.keep_mergefield); org.docx4j.model.fields.merge.mailmerger.performmerge(wordmlpackage, item, true); wordmlpackage.save(new file(outputfilepath)); return }
the ouput then:
2017-09-13 12:30:41.803 info 4296 --- [nio-9192-exec-1] org.docx4j.jaxb.context : java.vendor=oracle corporation 2017-09-13 12:30:41.803 info 4296 --- [nio-9192-exec-1] org.docx4j.jaxb.context : java.version=1.8.0_131 2017-09-13 12:30:41.827 info 4296 --- [nio-9192-exec-1] org.docx4j.jaxb.context : no moxy jaxb config found; assume not intended.. 2017-09-13 12:30:41.890 info 4296 --- [nio-9192-exec-1] o.d.jaxb.namespaceprefixmapperutils : using namespaceprefixmappersuninternal, suitable java 6 2017-09-13 12:30:41.890 info 4296 --- [nio-9192-exec-1] org.docx4j.jaxb.context : using java 6/7 jaxb implementation 2017-09-13 12:30:45.046 info 4296 --- [nio-9192-exec-1] org.docx4j.jaxb.context : not using moxy; using com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl 2017-09-13 12:30:45.214 warn 4296 --- [nio-9192-exec-1] org.docx4j.utils.resourceutils : couldn't resource: docx4j.properties 2017-09-13 12:30:45.215 warn 4296 --- [nio-9192-exec-1] org.docx4j.docx4jproperties : couldn't find/read docx4j.properties; docx4j.properties not found via classloader. 2017-09-13 12:30:45.215 info 4296 --- [nio-9192-exec-1] org.docx4j.xmlutils : using com.sun.org.apache.xerces.internal.jaxp.saxparserfactoryimpl 2017-09-13 12:30:45.215 info 4296 --- [nio-9192-exec-1] org.docx4j.xmlutils : using com.sun.org.apache.xerces.internal.jaxp.documentbuilderfactoryimpl 2017-09-13 12:30:45.226 info 4296 --- [nio-9192-exec-1] o.d.o.contenttype.contenttypemanager : detected wordprocessingml package 2017-09-13 12:30:45.227 info 4296 --- [nio-9192-exec-1] org.docx4j.openpackaging.io3.load3 : instantiated package of type org.docx4j.openpackaging.packages.wordprocessingmlpackage 2017-09-13 12:30:45.231 info 4296 --- [nio-9192-exec-1] org.docx4j.utils.xpathfactoryutil : xpath implementation: org.apache.xpath.jaxp.xpathfactoryimpl 2017-09-13 12:30:45.247 warn 4296 --- [nio-9192-exec-1] org.docx4j.openpackaging.io3.load3 : no jaxb model customxmldatastorage part; null 2017-09-13 12:30:45.260 warn 4296 --- [nio-9192-exec-1] org.docx4j.openpackaging.io3.load3 : no jaxb model customxmldatastorage part; null 2017-09-13 12:30:45.264 warn 4296 --- [nio-9192-exec-1] org.docx4j.openpackaging.io3.load3 : no jaxb model customxmldatastorage part; null 2017-09-13 12:30:45.281 info 4296 --- [nio-9192-exec-1] o.d.o.contenttype.contenttypemanager : using docpropscustompart ... 2017-09-13 12:30:45.289 info 4296 --- [nio-9192-exec-1] org.docx4j.openpackaging.io3.load3 : package read; elapsed time: 3509 ms 2017-09-13 12:30:45.643 info 4296 --- [nio-9192-exec-1] org.docx4j.xmlutils : using org.apache.xalan.transformer.transformerimpl 2017-09-13 12:30:45.833 info 4296 --- [nio-9192-exec-1] o.docx4j.model.fields.merge.mailmerger : found 0 fields 2017-09-13 12:30:45.860 info 4296 --- [nio-9192-exec-1] org.docx4j.xmlutils : using org.apache.xalan.transformer.transformerimpl 2017-09-13 12:30:45.898 info 4296 --- [nio-9192-exec-1] o.docx4j.model.fields.merge.mailmerger : found 0 fields 2017-09-13 12:30:45.904 info 4296 --- [nio-9192-exec-1] o.d.jaxb.namespaceprefixmapperutils : using namespaceprefixmappersuninternal, suitable java 6
the output says found 0 fields. have in order replace string? how should record in docx file like?
Comments
Post a Comment