@gbrunda In MS Word IF
field a whitespace is used as delimiter between parameters, so if field value of Description2
has a whitespace it is require to wrap it into double quotes. For example in the template you have the following field code:
{ IF { MERGEFIELD ProdType } = "XYZ" { MERGEFIELD Description1 } { MERGEFIELD Description2 } }
if you fill it with data without whitespaces like this:
Document doc = new Document("C:\\Temp\\in.docx");
doc.getMailMerge().setUnconditionalMergeFieldsAndRegions(true);
doc.getMailMerge().execute(new String[] { "ProdType", "Description1", "Description2" },
new String[] { "ProdType", "Description1", "Description2" });
doc.save("C:\\temp\\out.docx");
Double quotes are not required and the output will look like this:
{ IF ProdType = "XYZ" Description1 Description2 }
but if there are whitespaces:
Document doc = new Document("C:\\Temp\\in.docx");
doc.getMailMerge().setUnconditionalMergeFieldsAndRegions(true);
doc.getMailMerge().execute(new String[] { "ProdType", "Description1", "Description2" },
new String[] { "ProdType", "The first description", "The second description" });
doc.save("C:\\temp\\out.docx");
It is required to wrap the values into double quotes to make it possible to distinguish between true and false values in the IF
field and the result will look like this:
{ IF ProdType = "XYZ" "The first description" "The second description" }
in.docx (14.0 KB)
out.docx (11.4 KB)
It is normally is not allowed to use double quotes in IF field values. And the only way to have a double quite in the IF field is using an embedded field like this { QUOTE 34 }
.