Merge blocks repeat content and included merge fields based on given data rows of a specific child table or object. Content within this block can be filtered and sorted with build-in functionality of the Mail ╰ TX Text Control .NET for Windows Forms
╰ DocumentServer Namespace
╰ MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services. class. This demo shows how to vertically merge table cells in case the content is the same.
Sample Merge Block
Consider the following merge block template:
After merging some data into this block, the MailMerge class produces the following output:
In a post-merge process, the vertically adjacent cells with the same content should be merged as shown in the next illustration:
Mark Merge Block Tables
In a first step, a Block ╰ TX Text Control .NET for Windows Forms
╰ DocumentServer Namespace
╰ MailMerge Class
╰ BlockRowMerged Event
Occurs when a merge block row has been merged successfully. event is attached to mark the resulting tables of merge blocks. In a later process, we will search for these tables to process them:

In that event, the first cell is marked with the Name ╰ TX Text Control .NET for Windows Forms
╰ TXTextControl Namespace
╰ TableCell Class
╰ Name Property
Gets or sets the cell's name. block_identifier.

After the Merge ╰ TX Text Control .NET for Windows Forms
╰ DocumentServer Namespace
╰ MailMerge Class
╰ Merge Method
Merges a single instance of an arbitrary type into the loaded document template. method created the document, we look for all tables with the table marker and call the MergeSimilarCells method:

Comparing the Cells
The actual work is done in the MergeSimilarCells method that loops through all columns separately to find similar vertically adjacent cells with the same content. If cells are found with the same content, they are vertically merged and the cell's text is replaced with the common content.

This method must loop through the table twice (the function calls itself at the end) as complete rows are potentially merged which could result in more adjacent cells with the same content.
If the data is changed, so that cells in the columns Quantity and Price match, results look similar to the table shown in the next screenshot:
The vertical text alignment can be changed in the template, so that the merged table content is rendered in the middle of the table cell to generate a more readable layout:
Sample Project
This sample shows the flexibility of the MailMerge functionality. At any point, it is possible to interact during the merge process using the events or it is possible to manipulate the document after the merge process is finished.
Test this on your own by looking at the sample that is hosted in our GitHub account. This demo uses the Windows Forms version, but the code works with WPF and ASP.NET as well.