Populate Template with Data

In this article you will learn that how to populate Mail Merge or mustache template with data.

This API represents a controller for executing the mail merge.

The following is a description of the most important parameters:

Parameter NameDescription

Merge with regions or not. False by default.

Flag ‘withRegions’ can be omitted, in this case, a simple mail merge will be executed. If the flag is present and value is ‘true’ - mail merge with regions will be executed.

mailMergeDataFileIf mailMergeDataFile parameter exists, the data is taken from the server path (the parameter must contain the full path to the server file). However, if the mailMergeDataFile parameter is omitted, the data is expected in the requested content.

If the cleanup parameter is omitted, cleanup options will be None.


useWholeParagraphAsRegionSpecifies a value indicating whether paragraphs with TableStart or TableEnd field should be fully included in the mail merge region or particular range between TableStart and TableEnd fields. The default value is true.

The cleanup options parameter can contain a list of values from below, separated by “,":

NoneWithout any cleanup.
EmptyParagraphsSpecifies whether paragraphs that contained mail merge fields with no data should be removed from the document.
UnusedRegionsSpecifies whether unused mail merge regions should be removed from the document.
UnusedFieldsSpecifies whether unused merge fields should be removed from the document.
ContainingFieldsSpecifies whether fields that contain merge fields (for example, IFs) should be removed from the document if the nested merge fields are removed.
RemoveTitleRowRemoves title row of the table if this table doesn’t contain any rows except title row. It does not remove title rows in nested tables.
RemoveTitleRowInInnerTablesEnable “RemoveTitleRow " for nested tables.
RemoveStaticFieldsSpecifies whether static fields should be removed from the document. Static fields are fields, which results remain the same upon any document change. Fields, which do not store their results in a document and are calculated on the fly (like Aspose.Words.Fields.FieldType.FieldListNum, Aspose.Words.Fields.FieldType.FieldSymbol, etc.) are not considered to be static.


The OpenAPI Specification defines a publicly accessible programming interface and lets you carry out REST interactions directly from a web browser.

You can use cURL command-line tool to easily interact with Aspose.Words web services. The following example shows how to make calls to Cloud API with cURL.

Case 1: MailMerge Template

Feel free to download and explore sample input SampleMailMergeTemplate.docx, SampleMailMergeTemplateData.txt and output TestPostDocumentExecuteMailMerge.docx files designed to act as a demonstration and let you figure out the details quickly.

Case 2: Mustache Template

Feel free to download and explore sample input TestExecuteTemplate.doc, TestExecuteTemplateData.txt and output TestPostDocumentExecuteMailMergeResult.docx files designed to act as a demonstration and let you figure out the details quickly.

Cloud SDK Family

Using an SDK is the best way to speed up the development. An SDK takes care of low-level details and lets you focus on your project tasks.

Please check out the GitHub repository for a complete list of Aspose.Words SDKs.

The following code examples demonstrate how to make calls to Aspose.Words web services using various SDKs: