We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merge field dynamically

Is it possible to define and insert a merge field in word template and then populate its value in run time?

Hi Prashanth,

Thanks for your inquiry. Yes, you can achieve your requirement using Aspose.Words. Following code example inserts the mail merge field and perform simple mail merge. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertField("MERGEFIELD MyFieldName \\* MERGEFORMAT");
String[] input_names = new String[]{"MyFieldName"};
Object[] input_data = new Object[]{"Aspose.Words"};
doc.getMailMerge().execute(input_names, input_data);
doc.save(MyDir + "Out.docx");

Thanks for the response. but can we controller the place of new merge field, like add merge field at end of the document or end of the footer. Thanks.

Hi Prashanth,

Thanks for your inquiry. Yes, you can move cursor to any valid position in Document and insert merge field. Please refer to the following article:

I hope, this helps.

Best regards,