Products Technologies Demo Docs Blog Support Company

MailMerge: Removing Empty Blocks

The RemoveEmptyBlocks property introduced in TX Text Control X13 removes content from merge blocks that have no matching data during processing. Setting it to true on the MailMerge instance enables conditional template sections that appear or disappear based on data availability.

MailMerge: Removing Empty Blocks

In version X13, a new property has been introduced that specifies whether the content of empty merge blocks should be removed from the template or not: RemoveEmptyBlocks. This can be very helpful for dynamic templates where under specific circumstances, a complete block should be rendered or not.

Consider the following sample class structure that is used as the merge data object:

public class Data
{
    public string Field { get; set; }
    public Appendix Appendix { get; set; }
}

public class Appendix
{
    public string Field1 { get; set; }
}

The name of the dynamic block in the template is Appendix and the master object is Data. If the property Appendix of the class Data has been set to a valid object of type Appendix, the block data exists and is merged.

Appendix appendix = new Appendix()
{
    Field1 = "Field 1 Text"
};

Data data = new Data() {
    Field = "Field Text",
    Appendix = appendix
};

using (MailMerge mailMerge1 = new MailMerge())
{
    mailMerge1.TextComponent = textControl1;
    mailMerge1.RemoveEmptyBlocks =
        removeEmptyBlocksToolStripMenuItem.Checked;
    mailMerge1.MergeObject(data);
}

If the property RemoveEmptyBlocks of MailMerge is set to true (code line 14) and the merge data is missing (code line 8), the complete block gets removed.

This new concept allows you to create dynamic structures and conditional blocks in a template. Merge blocks are not necessarily blocks that repeat content. Using merge blocks, you can also define a named range of formatted text with data from another object.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingMail Merge

MailMerge Class Settings Explained

The MailMerge class provides four properties to control merge output: RemoveEmptyFields, RemoveEmptyLines, RemoveEmptyBlocks, and RemoveEmptyImages. Each property handles unmatched or missing data…


ReportingWindows FormsExcel

Merge Excel Documents into MailMerge Templates using IncludeText Fields

IncludeText fields in TX Text Control templates reference external Excel files during mail merge. The process loads .xlsx files as temporary ServerTextControl instances, using Bookmark to target…


ASP.NETReportingWindows Forms

MailMerge: Conditional Table Cell Colors using Filter Instructions

The TX Text Control MailMerge FieldMerged event exposes TableCell instances during merge for conditional formatting. A CellFilterInstructions class parses filter rules from merge field names and…


ASP.NETReportingWindows Forms

MailMerge: Using Filters to Remove Unwanted Rows

TX Text Control merge block filters remove unwanted rows from repeating data during the mail merge process without modifying the underlying source. Filter conditions applied to merge blocks…


ReportingWindows FormsMail Merge

MailMerge: Conditional Rendering of Merge Blocks

TX Text Control X16 provides two approaches to conditionally render merge blocks within MailMerge templates. Setting RemoveEmptyBlocks removes blocks when child data is absent, while…

Share on this blog post on: