MailMergeUseWholeParagraphAsRegion Property

Gets or sets a value indicating whether whole paragraph with TableStart or TableEnd field or particular range between TableStart and TableEnd fields should be included into mail merge region.

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


public bool UseWholeParagraphAsRegion { get; set; }

Property Value

Type: Boolean


The default value is true.


Shows the relationship between mail merge regions and paragraphs.
public void UseWholeParagraphAsRegion()
    // Create a document with 2 mail merge regions in one paragraph and a table to which can fill one of the regions during a mail merge
    Document doc = CreateSourceDocWithNestedMergeRegions();
    DataTable dataTable = CreateSourceTableDataTableForOneRegion();

    // By default, a paragraph can belong to no more than one mail merge region
    // Our document breaks this rule so executing a mail merge with regions now will cause an exception to be thrown
    Assert.Throws<InvalidOperationException>(() => doc.MailMerge.ExecuteWithRegions(dataTable));

    // If we set this variable to false, paragraphs and mail merge regions are independent so we can safely run our mail merge
    doc.MailMerge.UseWholeParagraphAsRegion = false;

    // Our first region is populated, while our second is safely displayed as unused all across one paragraph
    doc.Save(ArtifactsDir + "MailMerge.UseWholeParagraphAsRegion.docx");

/// <summary>
/// Create a document with two mail merge regions sharing one paragraph.
/// </summary>
private static Document CreateSourceDocWithNestedMergeRegions()
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.Write("Region 1: ");
    builder.InsertField(" MERGEFIELD TableStart:MyTable");
    builder.InsertField(" MERGEFIELD Column1");
    builder.Write(", ");
    builder.InsertField(" MERGEFIELD Column2");
    builder.InsertField(" MERGEFIELD TableEnd:MyTable");

    builder.Write(", Region 2: ");
    builder.InsertField(" MERGEFIELD TableStart:MyOtherTable");
    builder.InsertField(" MERGEFIELD TableEnd:MyOtherTable");

    return doc;

/// <summary>
/// Create a data table that can populate one region during a mail merge.
/// </summary>
private static DataTable CreateSourceTableDataTableForOneRegion()
    DataTable dataTable = new DataTable("MyTable");
    dataTable.Rows.Add(new object[] { "Value 1", "Value 2" });

    return dataTable;

See Also