Products Technologies Demo Docs Blog Support Company

MailMerge: Using Filters to Remove Unwanted Rows

Data in merge blocks can be filtered and sorted. This article explains how to use filters to remove unwanted lines.

MailMerge: Using Filters to Remove Unwanted Rows

Consider a use case where you don't have any influence on the structure of data you get from applications, APIs or other business layers to merge your templates for invoices or other reports.

In the following scenario, an invoice should be created based on JSON data from an ERP system. All invoice items are returned as line items plus a last line item that only contains the total price. The following JSON is used as a data source. In line 23-25, you can see a line item that only contains a price. This is the line in the final document we would like to filter out.

[
  {
    "Id":1,
    "Name":"Invoice",
    "Orders":[
      {
        "Id":1,
        "OrderItems":[
          {
            "Id":1,
            "Qty":5,
            "Product":{
              "Id":1,
              "Name":"TX Spell .NET",
              "Description":"Spell checking component",
              "Available":true,
              "Price":249.56,
              "Serial":"AA6765653"
            },
            "Price":200.56
          },
          [...],
          {
            "Price":4433.44
          }
        ]
      }
    ]
  }
]

As the total price should be calculated using a formula in the template, the last "line item" is not required. The following screenshot shows the template with the repeating block:

Template

After the data is merged into this template as is, the results show the "empty" line displaying only the total value:

Template

In order to remove this empty line, it is not required to manipulate the data. A merge block filter can be used to filter out the empty line. The block OrderItems is receiving a filter on the column Qty. If this field is empty, the row should not be rendered:

Template

The following screenshot shows the filtered results:

Template

You can download the template and the sample JSON here for your own tests.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETReportingWindows Forms

MailMerge: Conditional Table Cell Colors using Filter Instructions

The MailMerge class provides an extensible framework to inject custom logic to the merge process. This sample shows how to implement conditional table cell colors.


ASP.NETReportingWindows Forms

Different Ways to Create Documents using Text Control Products

There are many ways to create documents using Text Control products. This article gives an overview of different approaches using our products.


ActiveXASP.NETReporting

TX Text Control 32.0 Has Been Released

We are pleased to announce the immediate availability of TX Text Control 32.0 for all platforms including ASP.NET, Windows Forms, WPF and ActiveX.


ASP.NETWindows FormsWPF

An Ultimate Guide to Mail Merge with MS Word Documents in C#

The MailMerge class provides very effective ways to merge data into MS Word compatible templates. This updated ultimate guide provides an overview of all the important features and functionalities…


ActiveXASP.NETReporting

TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released

We are happy to announce the immediate availability of TX Text Control 31.0 for all platforms including ASP.NET, Windows Forms, WPF and ActiveX and TX Spell .NET 10.0 for all .NET based platforms.