Mail Merge and Reporting
Developers of WPF applications who create documents from data, such as invoices, contracts, letters and reports, find everything about templates and merging collected here. Users design a template in the TextControl of a window with the Reporting ribbon tab, and the MailMerge class, created in your code, fills it with data in the editor or in a ServerTextControl in the background. Once through, you know how data, fields and blocks fit together, how to shape and format the result and how the designer and the merge events work.
The tutorials of Getting Started: Mail Merge build a first template and merge it, and MailMerge in the Overview introduces the class. Mail merge requires the Professional or Enterprise edition; see Editions and Feature Availability.
How Mail Merge Works
Three parts come together in a merge:
- The template, an ordinary document designed in the Reporting tab, in MS Word or in code, holds merge fields for single values, merge blocks for repeated and optional parts, special fields such as
IFandINCLUDETEXT, and image and barcode placeholders. - The data arrives as business objects, a
DataSet, JSON or XML, shaped like the document, with names that match the fields and blocks. MailMergemerges the data into the template of aWPF.TextControlor aServerTextControl. The result appears in the editor or is saved as PDF, DOCX or another format, as one document or one per record.
Layout and rules stay in the template, so a designer can change them without a change to your code.

Find the Right Page
| If you want to | Read |
|---|---|
| Understand the reporting model, merge in the editor or in the background, create one document per record | Overview |
| Merge business objects, DataSets, JSON or XML | Data Sources |
| Format numbers and dates, add text before and after a value, insert date fields | Merge Fields |
| Repeat table rows or sections for each record | Merge Blocks |
| Build master-detail reports with blocks inside blocks | Nested Blocks and Master-Detail Reports |
| Reuse terms, letterheads or address blocks in many templates | Subtemplates |
| Merge logos, photos, QR codes and barcodes | Images and Barcodes |
| Include text and sections only when the data calls for them | Conditional Content |
| Merge the rows of a block in order and only the rows you need | Sorting and Filtering |
| Color rows, highlight values or calculate totals in merged tables | Formatting and Styling |
| Design, store and test templates that hold up with real data | Template Design |
| Know every button and dialog box of the WPF Reporting tab, or open them from your code | Reporting Ribbon and WPF Dialog Boxes |
| Show designers the merged result in the editor | Template Preview |
| Follow, change or cancel a merge in its events | Merge Events |
Recommended Order
- Overview: the reporting model and where the merge runs in a WPF application.
- Data Sources: the shapes of data you can merge.
- Merge Fields and Merge Blocks: the building blocks of templates.
- Reporting Ribbon and WPF Dialog Boxes and Template Design: the designer for your users.
Pages in This Section
- Overview — the reporting model, pre-shaped data and one document per record.
- Data Sources — objects, DataSets, JSON and XML.
- Merge Fields — formats, text before and after a value, date and form fields.
- Merge Blocks — repeating parts of a template.
- Nested Blocks and Master-Detail Reports — blocks inside blocks.
- Subtemplates — documents included by
INCLUDETEXTfields. - Images and Barcodes — placeholders filled from the data.
- Conditional Content —
IFfields, optional blocks and conditions. - Sorting and Filtering — rules that blocks carry.
- Formatting and Styling — formatting from the template and from events.
- Template Design — designing, storing and testing templates.
- Reporting Ribbon and WPF Dialog Boxes — the WPF Reporting tab, its dialog boxes and their classes.
- Template Preview — merged records in the editor while designing.
- Merge Events — the .NET events of
MailMergeand their order.