Free Support Forum - aspose.com

Mail Merge Template

Hello, Instead of creating Mail Merge document template using MS Word, is it possible to build the mail merge document template and define the fields and regions etc.. using Aspose.Words Component for .NET

If it is possible a small code snipest of KB would be appreciated.

Thanks and regards

Austin

Hi <?xml:namespace prefix = st1 ns = "urn:schemas:contacts" />Austin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Sure, you can build mail merge template from scratch. Please see the following link to learn how to insert merge fields using DocumentBuilder:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.documentbuilder.insertfield.html

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.

Thanks Alexey.

Really appreicate your prompt reply. I am sorry to say that I am unable to insert a Field to a document file.

It is not giving me error and genereating the file successfully. but not inserting the Field in it. below is my code..

Document document = new Document();

DocumentBuilder docBuilder = new DocumentBuilder(document);

docBuilder.InsertField(@"MERGEFIELD FirstName \* MERGEFORMAT","");

document.Save("helloworld.doc");

Thanks for the help..

Hi <?xml:namespace prefix = st1 ns = "urn:schemas:contacts" />Austin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Actually merge field is there, you just do not see it, because you did not specify field value:

builder.InsertField(@"MERGEFIELD FirstName \* MERGEFORMAT", "");

You can press Alt+F9 to see the field. Also, you can specify field value during inserting the field:

Document document = new Document();

DocumentBuilder builder = new DocumentBuilder(document);

builder.InsertField(@"MERGEFIELD FirstName \* MERGEFORMAT", "Ā«FirstNameĀ»");

document.Save(@"Test001\out.doc");

Best regards.