Creating and Merging MS Word Compatible Templates

Mail merge is the most typical application for TX Text Control. The combination of TX Text Control's MS Word compatible field functionality and TX Text Control .NET Server's automated MailMerge component is a very powerful toolset to build high peformance and MS Word compatible mail merge applications.

TX Text Control supports not only the merge process, but also provides the required editor functionality to create templates with a true WYSIWYG interface.

This sample project shows most of the mail merge possibilities of TX Text Control. The following steps are included:

It is quite similar to MS Word mail merge capabilities, but it comes with source code and can be customized completely. The following tutorial explains how to use this sample.

1. Connect to a database

Now you can see the contained DataTables in the drop down box of the toolbar. If the database would contain more DataTables, you could select the required DataTable from this box. Based on the selected database and DataTable, the contained merge fields are automatically added to the Insert Field drop down button and the Insert Merge Field menu item.

2. Insert merge fields

3. Export the document

This opens a new form that consists of a TX Text Control and a simple toolbar. The DocumentServer.MailMerge component is used in the background to merge the created template with the data records from the selected database. The resulting document is copied into the visual TX Text Control instance on the form. The actual merge process is done in 3 lines of code:

[C#]
mailMerge.TextComponent = tx;
mailMerge.LoadTemplateFromMemory(Document,
TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat);
mailMerge.Merge(DataTable, true);
[Visual Basic]
mailMerge.TextComponent = tx
mailMerge.LoadTemplateFromMemory(Document, _
	TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat)
mailMerge.Merge(DataTable, True)

<< Previous Next >>