I wanted to use docx4j.NET to automate the creation of address labels. A basic docx file with merge fields separated by the "next record" instruction, the latter seems to be ignored when merging.
I get pages filled with one address duplicated in each label cell (plus the "next record" token). e.g. for 10 addresses I do not get one page with ten addresses but I get 10 pages each having 10 labels filled with the same address.
Can anyone confirm or do I have to change either my code or the docx file?
Here the code I use:
private static void mergeLabels() {
java.util.List data = new java.util.ArrayList();
java.util.Map map = new java.util.HashMap();
map.put(new DataFieldName("First_Name"), "John");
map.put(new DataFieldName("Last_Name"), "Doe");
data.add(map);
map = new java.util.HashMap();
map.put(new DataFieldName("First_Name"), "Jane");
map.put(new DataFieldName("Last_Name"), "Joe");
data.add(map);
string flInput = @"e:\docx4j\input.docx";
string flOutput = @"e:\docx4j\output.docx";
java.io.File inFile = new java.io.File(flInput);
WordprocessingMLPackage template = WordprocessingMLPackage.load(inFile);
MailMerger.setMERGEFIELDInOutput(OutputField.KEEP_MERGEFIELD);
WordprocessingMLPackage merged = MailMerger.getConsolidatedResultCrude(template, data);
java.io.File outFile = new java.io.File(flOutput);
merged.save(outFile);
}