i want use my templates with some placeholder for dinamically replace.
I read this topic (http://dev.plutext.org/forums/viewtopic.php?f=6&t=6&sid=43f1d4b2a5fa55a3c6746ed0c72ecb96), but i found this solution a lot impractical.
I want test this solution:
- Code: Select all
//read template file
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File(templateFileWithPlaceHolder));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Document wmlDocumentEl1 = (Document) documentPart.getJaxbElement();
org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
.getJaxbElement();
//xml --> string
String xml = XmlUtils.marshaltoString(wmlDocumentEl, true);
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("PROP1", "bla");
mappings.put("PROP2", "bla bla");
//valorize template
Object obj = XmlUtils.unmarshallFromTemplate(xml, mappings);
//change JaxbElement
documentPart.setJaxbElement(obj);
SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
//save new documnt
saver.save(newFile);
No errors... but the new file is identical to templateFileWithPlaceHolder.
Thank's in advance
Fiorenzo