Page 1 of 1

Generated word document not replacing fieldvalue

PostPosted: Wed Jan 15, 2014 10:28 pm
by satish_jadhav
Hi,

I have written java class to use word document template to generate word document. Please find the program below, which runs without error but the generated word document is not replacing the fieldname.

Could any one help to rectify the issue?

public static void main(String[] args) throws Exception {

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(
new java.io.File("FAX.docx"));
List<Map<DataFieldName, String>> data = new ArrayList<Map<DataFieldName, String>>();
Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
map.put( new DataFieldName("GREETINGLINE"), "Daffy duck");
//map.put( new DataFieldName("SubTitle"), "Plutext");
//map.put(new DataFieldName("Kundenstrasse"), "Bourke Street");
data.add(map);
//map = new HashMap<DataFieldName, String>();
//map.put( new DataFieldName("Kundenname"), "Jason");
//map.put(new DataFieldName("Kundenstrasse"), "Collins Street");

// data.add(map);
System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
WordprocessingMLPackage output = org.docx4j.model.fields.merge.MailMerger.getConsolidatedResultCrude(wordMLPackage, data);
System.out.println(XmlUtils.marshaltoString(output.getMainDocumentPart().getJaxbElement(), true, true));
output.save(new java.io.File("mergefield1-OUT.docx") );
}

Re: Generated word document not replacing fieldvalue

PostPosted: Thu Jan 16, 2014 6:21 am
by jason
You'll need to upload your input FAX.docx so we can look at its contents; alternatively unzip and attach the relevant part of its document.xml