Since version 16.0 of TX Text Control .NET Server, the MailMerge class supports the merging of nested blocks. The component recursively descents into the tree structure and merges the contained fields with the corresponding relational data.
In this sample, a report should list the "sick leave hours" and "vacation days" of all employees of a purely fictional company. The template contains static content, dynamic content for each employee and nested dynamic content for each specific employee record.
- Static content
-Heading: "Accruals Report"
-Page number: "Page n"
- Dynamic content
-Company name: "Software Consultants, LLC"
-Date
- Dynamic content for each employee
-Employee number
-Employee name
- Nested dynamic content for each employee
-Date
-Type
-Action
-Note
-Hours
-Balance
The above described content sections are marked in the following template illustration:
A repeating block can be any contiguous block of text in a template that is marked with specifically named DocumentTargets at the beginning and the end. The following screenshot shows such a repeating block in the TX Template Designer.
Using the MailMerge component that comes with the TX Text Control .NET Server licenses, the merge process is very easy. You don't need to iterate through the text fields and you don't need to care about the repeating blocks. The whole process is done automatically - including the nested blocks. The following code shows the required calls of the MailMerge component:
How to use this sample?
Assuming that you loaded this project into Visual Studio and started this project, the following steps are required to create a report:
1. Click on Load XML... from the Report main menu, browse for the data.xml file that comes with the sample and Open it.
2. Click on Load... from the Template main menu, browse for the Accruals Report.docx file and confirm with Open.
3. Finally, click the Create Report button in the button bar to start the merge process.
The following screenshot shows the merged report document that can be printed or exported as an Adobe PDF file.
Test this sample now and download the sources in our source code library.
About TX Text Control:
TX Text Control was originally released in 1991, since then more than 40,000 copies have been sold. Starting off as a single, small DLL, TX Text Control has made its way through 16-bit DLL and VBX versions to today‘s Enterprise edition with its .NET and ActiveX components. The recent addition to the family, TX Text Control .NET Server, offers all of TX Text Control advanced word processing functionality in an easy-to-use server-side .NET component. Customers benefit from these years of experience, large user base, and at the same time, appreciate developing with a mature, reliable product.
Contact Informations:
support@textcontrol.com
North & South America:
Phone: +1 704-370-0110
Phone: +1 877-462-4772 (toll free)
Europe:
Phone: +49 (0)421 42 70 67 10
Asia Pacific:
Phone: +886 2-2797-8508
In this sample, a report should list the "sick leave hours" and "vacation days" of all employees of a purely fictional company. The template contains static content, dynamic content for each employee and nested dynamic content for each specific employee record.

- Static content
-Heading: "Accruals Report"
-Page number: "Page n"
- Dynamic content
-Company name: "Software Consultants, LLC"
-Date
- Dynamic content for each employee
-Employee number
-Employee name
- Nested dynamic content for each employee
-Date
-Type
-Action
-Note
-Hours
-Balance
The above described content sections are marked in the following template illustration:

A repeating block can be any contiguous block of text in a template that is marked with specifically named DocumentTargets at the beginning and the end. The following screenshot shows such a repeating block in the TX Template Designer.

Using the MailMerge component that comes with the TX Text Control .NET Server licenses, the merge process is very easy. You don't need to iterate through the text fields and you don't need to care about the repeating blocks. The whole process is done automatically - including the nested blocks. The following code shows the required calls of the MailMerge component:
VB.NET:
mailMerge1.LoadTemplateFromMemory(data,
TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat);
// load the XML file
DataSet ds = new DataSet();
ds.ReadXml(tbDatabaseFile.Tag.ToString(), XmlReadMode.Auto);
// add the relations for the nested blocks
DataRelation relation_sick = new DataRelation("sick",
ds.Tables["employee"].Columns["dyn_employee_number"],
ds.Tables["sick"].Columns["dyn_employee_number"]);
DataRelation relation_vacation = new DataRelation("vacation",
ds.Tables["employee"].Columns["dyn_employee_number"],
ds.Tables["vacation"].Columns["dyn_employee_number"]);
ds.Relations.Add(relation_vacation);
ds.Relations.Add(relation_sick);
// pass the data
mailMerge1.MergeBlocks(ds);
mailMerge1.Merge(ds.Tables["general"], true);
How to use this sample?
Assuming that you loaded this project into Visual Studio and started this project, the following steps are required to create a report:
1. Click on Load XML... from the Report main menu, browse for the data.xml file that comes with the sample and Open it.
2. Click on Load... from the Template main menu, browse for the Accruals Report.docx file and confirm with Open.
3. Finally, click the Create Report button in the button bar to start the merge process.
The following screenshot shows the merged report document that can be printed or exported as an Adobe PDF file.

Test this sample now and download the sources in our source code library.
About TX Text Control:
TX Text Control was originally released in 1991, since then more than 40,000 copies have been sold. Starting off as a single, small DLL, TX Text Control has made its way through 16-bit DLL and VBX versions to today‘s Enterprise edition with its .NET and ActiveX components. The recent addition to the family, TX Text Control .NET Server, offers all of TX Text Control advanced word processing functionality in an easy-to-use server-side .NET component. Customers benefit from these years of experience, large user base, and at the same time, appreciate developing with a mature, reliable product.
Contact Informations:
support@textcontrol.com
North & South America:
Phone: +1 704-370-0110
Phone: +1 877-462-4772 (toll free)
Europe:
Phone: +49 (0)421 42 70 67 10
Asia Pacific:
Phone: +886 2-2797-8508