A key concept and advantage of Text Control Reporting is the fact that the template doesn't store any database connection information which makes a template reusable, even if your database changes.

A template simply contains merge field and table names for merge blocks. When a new database structure is in use, all you need to do is to change the field names. Also, when reusing legacy templates from MS Word, you can easily change the field names and use this template for the merging process using TX Text Control.

As part of a feasibility study for a customer in our consulting unit, we created a dialog prototype that helps users to remap merge fields to new data sources.

We thought to share this project as it might be helpful for your own applications. The following screenshot shows this dialog in action:

[Click image to enlarge]

The creation of the dialog is very easy. As parameters, a DataSet for the new data and the template path is required:

// create a new DataSet and read the XML file
DataSet ds = new DataSet();
ds.ReadXml("sample_db.xml", XmlReadMode.Auto);
// create a new dialog and use the DataSet and template as parameters
FieldRemappingDialog frmFieldMapping =
new FieldRemappingDialog(
"invoice.docx",
TXTextControl.StreamType.WordprocessingML, ds);
frmFieldMapping.ShowDialog();
view raw Main.cs hosted with ❤ by GitHub

The dialog itself is very easy to use. Using the Next and Back buttons, you can navigate through the merge fields. The selected field can be replaced with a new data column name by clicking a field name in the left hand side list view box. The drop-down box Select Data Table can be used to switch between the available DataTables.

On closing the dialog, the template changes can be saved.

This sample project shows a lot of tricks and nice little features such as how to scroll to and highlight a field or how to navigate through existing fields in a document.

Download or fork the project on GitHub and browse the commented code. Feel free to use this sample for your own applications. Happy coding!