Hi Team,
We can insert Mail Merge filed in word document using the insert link in word document and can save that word document as template and use that filed in writing the information through code or in our program.
Could you please let me know, Is there any way that we can also insert Mail Merge field at any suitable position through code also?
Please revert in case of any issue.
Thanks,
Rajesh
Hi Rajesh,
Thanks for your inquiry. There are two ways you can use to insert merge field in document:
- Using DocumentBuilder.InsertField method as follows:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField(" MERGEFIELD mf ");
doc.Save(MyDir + @"15.3.0.docx");
- Using DOM class FieldMergeField:
Document doc = new Document();
Paragraph para = doc.FirstSection.Body.FirstParagraph;
FieldMergeField mergeField = (FieldMergeField)para.AppendField(FieldType.FieldMergeField, false);
mergeField.FieldName = "mf";
doc.Save(MyDir + @"15.3.0.docx");
I hope, this helps.
Best regards,