DocumentMailMerge Property

Returns a MailMerge object that represents the mail merge functionality for the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.12.0


public MailMerge MailMerge { get; }

Property Value

Type: MailMerge


Shows how to execute a mail merge with data from a DataTable.
public void ExecuteDataTable()
    DataTable table = new DataTable("Test");
    table.Rows.Add(new object[] { "Thomas Hardy", "120 Hanover Sq., London" });
    table.Rows.Add(new object[] { "Paolo Accorti", "Via Monte Bianco 34, Torino" });

    // Below are two ways of using a DataTable as the data source for a mail merge.
    // 1 -  Use the entire table for the mail merge to create one output mail merge document for every row in the table:
    Document doc = CreateSourceDocExecuteDataTable();


    doc.Save(ArtifactsDir + "MailMerge.ExecuteDataTable.WholeTable.docx");

    // 2 -  Use one row of the table to create one output mail merge document:
    doc = CreateSourceDocExecuteDataTable();


    doc.Save(ArtifactsDir + "MailMerge.ExecuteDataTable.OneRow.docx");

/// <summary>
/// Creates a mail merge source document.
/// </summary>
private static Document CreateSourceDocExecuteDataTable()
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.InsertField(" MERGEFIELD CustomerName ");
    builder.InsertField(" MERGEFIELD Address ");

    return doc;

ExpandedSee Also