The TXTextControl.DocumentServer.MailMerge class provides an extensible framework to inject custom logic to the merge process. The TXTextControl.DocumentServer.MailMerge.FieldMerged event can be used to manipulate the results, but also gives access to the surrounding TXTextControl.TableCell object.

This combination allows creative implementations such as conditional table cell colors based on specific filter instructions.

In the following sample, the table cell Qty should be highlighted red, if quantity is higher than 10, otherwise it should be green.

Template before the merge

These conditions can be adjusted in the following dialog:

Custom dialog

When merging the document, the conditions are evaluated in the custom events:

Merge results

The class CellFilterInstructions contains the instructions for the custom filter:

Loading...

This class is serialized as JSON and stored in the TXTextControl.TableCell.Name property. When a new dialog is opened, the JSON is deserialized and passed to the dialog. After changes are made, the object is stored as a serialized JSON string back in the TableCell.Name property.

Loading...

In the FieldMerging event, the instructions are evaluated and the custom background color is applied to the cell that is returned in the event arguments:

Loading...

Test this sample on your own and download the GitHub repository:

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2017 or better
  • TX Text Control .NET for Windows Forms (trial sufficient)