MailMergeMergeWholeDocument Property

Gets or sets a value indicating whether fields in whole document is updated while executing of a mail merge with regions.

Namespace:  Aspose.Words.MailMerging
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.9.0


public bool MergeWholeDocument { get; set; }

Property Value

Type: Boolean


The default value is false.


Shows the relationship between mail merges with regions and field updating.
public void MergeWholeDocument(bool doMergeWholeDocument)
    // Create a document and data table that will both be merged
    Document doc = CreateSourceDocMergeWholeDocument();
    DataTable dataTable = CreateSourceTableMergeWholeDocument();

    // A regular mail merge will update all fields in the document as part of the procedure,
    // which will happen if this property is set to true
    // Otherwise, a mail merge with regions will only update fields
    // within a mail merge region which matches the name of the DataTable
    doc.MailMerge.MergeWholeDocument = doMergeWholeDocument;

    // If true, all fields in the document will be updated upon merging
    // In this case that property is false, so the first QUOTE field will not be updated and will not show a value,
    // but the second one inside the region designated by the data table name will show the correct value
    doc.Save(ArtifactsDir + "MailMerge.MergeWholeDocument.docx");

    Assert.AreEqual(doMergeWholeDocument, doc.GetText().Contains("This QUOTE field is outside of the \"MyTable\" merge region."));

/// <summary>
/// Create a document with a QUOTE field outside and one more inside a mail merge region called "MyTable"
/// </summary>
private static Document CreateSourceDocMergeWholeDocument()
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Insert QUOTE field outside of any mail merge regions
    FieldQuote field = (FieldQuote)builder.InsertField(FieldType.FieldQuote, true);
    field.Text = "This QUOTE field is outside of the \"MyTable\" merge region.";

    // Start "MyTable" merge region
    builder.InsertField(" MERGEFIELD TableStart:MyTable");

    // Insert QUOTE field inside "MyTable" merge region
    field = (FieldQuote)builder.InsertField(FieldType.FieldQuote, true);
    field.Text = "This QUOTE field is inside the \"MyTable\" merge region.";

    // Add a MERGEFIELD for a column in the data table, end the "MyTable" region and return the document
    builder.InsertField(" MERGEFIELD MyColumn");
    builder.InsertField(" MERGEFIELD TableEnd:MyTable");

    return doc;

/// <summary>
/// Create a simple data table that will be used in a mail merge.
/// </summary>
private static DataTable CreateSourceTableMergeWholeDocument()
    DataTable dataTable = new DataTable("MyTable");
    dataTable.Rows.Add(new object[] { "MyValue" });

    return dataTable;

See Also