Dialog Project: Remapping Merge Fields
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…

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();
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!
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2012 or better
- TX Text Control .NET Server (trial sufficient)
Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
.NET C# PDF Generation Techniques: Which Method is Right for Your Project?
This article explains the distinct advantage TX Text Control offers with its true WYSIWYG (What You See Is What You Get) template system, where templates are designed visually, similar to…
Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C#…
This article provides best practices for mail merge and form field processing in ASP.NET Core C# applications using TX Text Control .NET Server. It shows how to use the Document Editor to create…
Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF…
This article shows the advantages of flow type layout reporting compared to banded reporting or populating PDF placeholders in .NET C#. It explains the differences and the benefits of using a flow…
TX Text Control 32.0 Has Been Released
We are pleased to announce the immediate availability of TX Text Control 32.0 for all platforms including ASP.NET, Windows Forms, WPF and ActiveX.
Getting Started: Angular Document Editor Attributes Explained
This article explains the possible attributes that can be used when initializing the TX Text Control Document Editor for Angular.