╰ DocumentServer Namespace
╰ MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services. class of TX Text Control uses MS Word compatible merge fields to populate data from various data sources into templates. In order to use legacy templates from other formats, such as HTML, placeholders can be converted into merge fields.
A typical legacy HTML template contains textual placeholders like in the following HTML:
In order to use the full power of Text Control's reporting engine, those templates should be converted into the TX Text Control internal format or an MS Word format such as Office Open XML (DOCX).
With TX Text Control's API, it is possible to load these HTML documents, find these placeholders and convert them into merge fields that can be directly used with MailMerge.
In order to find the placeholders like in the sample template above, the following extension method can be used to find them using a simple regular expression:
The extension method extends the Find method of TX Text Control to search for matches based on a given regular expression pattern:
In our sample, the template placeholder format is:
The extension Find method returns a MatchCollection that is then used to select the text in order to create a new Merge
╰ DocumentServer.Fields Namespace
╰ MergeField Class
The MergeField class implements the MS Word specific MERGEFIELD field. based on the selected text. After the text is removed, the newly created merge fields is then inserted into the document at the current input position:
After all placeholders have been converted to merge fields, the template can be used like any other MailMerge template to create documents.