My goal is to populate a word document template with data.
I have text fields, and I also have to populate a checkbox.
To do the text fields, I use this method:
- Code: Select all
HashMap<String, String> tokens = new HashMap<String, String>();
tokens.put("TOKEN_HOLDER", MiscSiteConfig.getCurrentVAPrivacyOfficer().getName().toString());
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(checkList));
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
org.docx4j.wml.Document wmlDocumentEl = mainDocumentPart.getJaxbElement();
String xml = XmlUtils.marshaltoString(wmlDocumentEl, true);
Document doc = (Document) XmlUtils.unmarshallFromTemplate(xml, tokens);
mainDocumentPart.setJaxbElement(doc);
This seems to work fine by itself ...