MailMergeUnconditionalMergeFieldsAndRegions Property

Gets or sets a value indicating whether merge fields and merge regions are merged regardless of the parent IF field's condition.

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

Syntax

public bool UnconditionalMergeFieldsAndRegions { get; set; }

Property Value

Type: Boolean

Remarks

The default value is false.

Examples

Shows how to merge fields or regions regardless of the parent IF field's condition.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a MERGEFIELD nested inside an IF field
// Since the statement of the IF field is false, the result of the inner MERGEFIELD will not be displayed
// and the MERGEFIELD will not receive any data during a mail merge
FieldIf fieldIf = (FieldIf)builder.InsertField(" IF 1 = 2 ");
builder.MoveTo(fieldIf.Separator);
builder.InsertField(" MERGEFIELD  FullName ");

// We can still count MERGEFIELDs inside IF fields with false statements if we set this flag to true
doc.MailMerge.UnconditionalMergeFieldsAndRegions = doCountAllMergeFields;

DataTable dataTable = new DataTable();
dataTable.Columns.Add("FullName");
dataTable.Rows.Add("James Bond");

// Execute the mail merge
doc.MailMerge.Execute(dataTable);

// The result will not be visible in the document because the IF field is false, but the inner MERGEFIELD did indeed receive data
doc.Save(ArtifactsDir + "MailMerge.UnconditionalMergeFieldsAndRegions.docx");

if (doCountAllMergeFields)
    Assert.AreEqual("\u0013 IF 1 = 2 \"James Bond\"\u0014\u0015", doc.GetText().Trim());
else
    Assert.AreEqual("\u0013 IF 1 = 2 \u0013 MERGEFIELD  FullName \u0014«FullName»\u0015\u0014\u0015", doc.GetText().Trim());

See Also