TX Text Control .NET for Windows Forms

Sample: Mail Merge with Repeating Blocks

The DocumentServer.MailMerge component can not only merge single fields in a template. Additionally, blocks can be defined that are repeated based on the number of specified data rows.

A MergeBlock is a region in a document that will be repeated in the merge process. This block can be easily inserted using the shipped TX Text Control Words. A MergeBlock's start and end is marked by two document targets with special names. The start and end of a merge block must either be in the floating text, comprising of one or more table rows as a whole or inside a single table cell. The following illustration shows an example of such a block start and end with their special names (in red) in detail:

The format of the target name is as follows:

blockStart_ + unique name

blockEnd_ + unique name

Sample:

blockStart_block1

blockEnd_block1

Load the sample program from the MailMerge_Blocks directory and start it. Automatically, a template is loaded that consists of simple merge fields and a repeating block which is basically the second row of the table.

Choose Merge from the MailMerge main menu to start the merge process. With a very few lines of code, the template is loaded and the data is merged using the DocumentServer.MailMerge component.

[C#] private DataSet dsAddresses; dsAddresses = new DataSet(); dsAddresses.ReadXml(Application.StartupPath + "\\data.xml"); TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings(); ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord; textControl1.Load(Application.StartupPath + "\\template.docx", TXTextControl.StreamType.WordprocessingML, ls); mailMerge1.MergeBlocks(dsAddresses); mailMerge1.Merge(dsAddresses.Tables["address"], true);
[Visual Basic] Private dsAddresses As DataSet dsAddresses = New DataSet() dsAddresses.ReadXml(Application.StartupPath + "\data.xml") Dim ls As New TXTextControl.LoadSettings() ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord textControl1.Load(Application.StartupPath + "\template.docx", TXTextControl.StreamType.WordprocessingML, ls) mailMerge1.MergeBlocks(dsAddresses) mailMerge1.Merge(dsAddresses.Tables("address"), True)

Continue with the next sample

 
 
Call us: +1 704-544-7445 (United States)
 
 

Products

Support

Downloads

Corporate

Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner