WField field = paragraph.AppendField("If", FieldType.FieldIf) as WField; field.FieldCode = "IF "; int fieldIndex = paragraph.Items.IndexOf(field); WMergeField mergeField = new WMergeField(document); mergeField.FieldCode = "MERGEFIELD Gender"; paragraph.Items.Insert(fieldIndex + 1, mergeField); WTextRange text = new WTextRange(document); text.Text = " = \"M\" \"Male\" \"Female\""; paragraph.Items.Insert(fieldIndex + 2, text); string[] fieldName = { "Gender" }; string[] fieldValue = { "F" }; document.MailMerge.Execute(fieldName, fieldValue); document.UpdateDocumentFields(); document.Save("Sample.docx", FormatType.Docx);
Hi Suganya,
The aforementioned code snippet (https://www.syncfusion.com/forums/121128/if-conditions-in-mailmerge-template?reply=lEp3NS ) is not working with DocIO v20.2.
Can you please verify and send a sample compatible with the latest version.
Regards,
Hari
Hi Hari,
Essential DocIO library process the merge fields within the field code of If
fields.
From v16.1.0.24, we have migrated the field to the new structure. So, you have
faced the problem in that old sample code
example which has the old field structure.
Please refer the below link to know more about this migration,
https://help.syncfusion.com/file-formats/release-notes/migratingtov16.1.0.24
We have prepared the sample application in the latest version to process
the merge fields within the field code of If fields as per your requirement and
it can be downloaded from the below link.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample-2029884514
Please refer our UG documentation link to know more about mail merge in the
Word document.
https://help.syncfusion.com/file-formats/docio/working-with-mail-merge
Regards,
Anto Nihil S
Hi Anto,
Thanks for your input. The sample works perfect.
Further to your sample, If I may ask - what can be done to include merge fields as a true or false statement in the IF field.
i.e. { IF 1=1 <<MergeField>> False } - I want to show the true expression as a merge field value.
Regards,
Hari
Hi Hari,
From the given details, we have found that your
requirement is to include merge fields as a true or false statement in the IF
field.
We have prepared the sample application to show the true expression as a merge
field value as per your requirement and it can be downloaded from the below attachment.
Regards,
Suriya Balamurugan.