# Mail Merge and Reporting

> Create documents from templates in WPF: the Reporting ribbon tab, MailMerge in code, data sources, merge fields and blocks, preview, styling and events.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Mail Merge and Reporting
- **1462 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/llms-full.txt

---

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](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/mail-merge/llms-full.txt) build a first template and merge it, and [MailMerge](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/mailmerge/llms-full.txt) in the Overview introduces the class. Mail merge requires the Professional or Enterprise edition; see [Editions and Feature Availability](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/editions/llms-full.txt).

### 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 `IF` and `INCLUDETEXT`, 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.
- **`MailMerge`** merges the data into the template of a `WPF.TextControl` or a `ServerTextControl`. 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.

![The Reporting tab of the WPF ribbon with the groups Data Source, Merge Fields, Merge Blocks and View](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/ribbon-reporting-tab.e14e49fb.webp)

### 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](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/overview/llms-full.txt) |
| Merge business objects, DataSets, JSON or XML | [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/data-sources/llms-full.txt) |
| Format numbers and dates, add text before and after a value, insert date fields | [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt) |
| Repeat table rows or sections for each record | [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/llms-full.txt) |
| Build master-detail reports with blocks inside blocks | [Nested Blocks and Master-Detail Reports](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/nested-blocks/llms-full.txt) |
| Reuse terms, letterheads or address blocks in many templates | [Subtemplates](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/subtemplates/llms-full.txt) |
| Merge logos, photos, QR codes and barcodes | [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/images-barcodes/llms-full.txt) |
| Include text and sections only when the data calls for them | [Conditional Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/conditional-content/llms-full.txt) |
| Merge the rows of a block in order and only the rows you need | [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/sorting-filtering/llms-full.txt) |
| Color rows, highlight values or calculate totals in merged tables | [Formatting and Styling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/styling/llms-full.txt) |
| Design, store and test templates that hold up with real data | [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt) |
| Know every button and dialog box of the WPF Reporting tab, or open them from your code | [Reporting Ribbon and WPF Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms-full.txt) |
| Show designers the merged result in the editor | [Template Preview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-preview/llms-full.txt) |
| Follow, change or cancel a merge in its events | [Merge Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/events/llms-full.txt) |

### Recommended Order

1. [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/overview/llms-full.txt): the reporting model and where the merge runs in a WPF application.
2. [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/data-sources/llms-full.txt): the shapes of data you can merge.
3. [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt) and [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/llms-full.txt): the building blocks of templates.
4. [Reporting Ribbon and WPF Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms-full.txt) and [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt): the designer for your users.

### Pages in This Section

- [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/overview/llms-full.txt) — the reporting model, pre-shaped data and one document per record.
- [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/data-sources/llms-full.txt) — objects, DataSets, JSON and XML.
- [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt) — formats, text before and after a value, date and form fields.
- [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/llms-full.txt) — repeating parts of a template.
- [Nested Blocks and Master-Detail Reports](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/nested-blocks/llms-full.txt) — blocks inside blocks.
- [Subtemplates](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/subtemplates/llms-full.txt) — documents included by `INCLUDETEXT` fields.
- [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/images-barcodes/llms-full.txt) — placeholders filled from the data.
- [Conditional Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/conditional-content/llms-full.txt) — `IF` fields, optional blocks and conditions.
- [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/sorting-filtering/llms-full.txt) — rules that blocks carry.
- [Formatting and Styling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/styling/llms-full.txt) — formatting from the template and from events.
- [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt) — designing, storing and testing templates.
- [Reporting Ribbon and WPF Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms-full.txt) — the WPF Reporting tab, its dialog boxes and their classes.
- [Template Preview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-preview/llms-full.txt) — merged records in the editor while designing.
- [Merge Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/events/llms-full.txt) — the .NET events of `MailMerge` and their order.

### Related Sections

- [Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/llms-full.txt): the WPF editor in which templates are designed.
- [Document Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/llms-full.txt): change merged documents with `ServerTextControl`.
- [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/llms-full.txt): PDF/A documents and forms from merged documents.
- [Mail Merge Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mail-merge/llms-full.txt): the TX Words Reporting sample and other applications.

---

## In This Section

- [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/llms-full.txt): Repeat content with merge blocks in WPF: InsertMergeBlockDialog results, paragraph blocks with MergeBlockSettings, GetBlockNames and the current block.
- [Conditional Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/conditional-content/llms-full.txt): Conditional content in WPF mail merge: IF fields created with IfField, blocks for optional sections, BlockMergingCondition, IncludeTextMerging and FieldMerged.
- [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/data-sources/llms-full.txt): Data sources for mail merge in WPF: objects, DataSets, JSON and XML, the MailMerge method for each and the DataSourceManager of the WPF Reporting tab.
- [Merge Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/events/llms-full.txt): Use the .NET events of MailMerge in WPF: FieldMerged, BlockMerging, BlockRowMerged, DataRowMerged and more, their order, a merge log and Cancel.
- [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt): Set MergeField options in WPF: numeric and date formats in all text parts, DateField, a text for fields without data, HTML values and FormFieldMergeType.
- [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/images-barcodes/llms-full.txt): Fill image and barcode placeholders in WPF: TXTextControl.Image, the WPF TXBarcodeControl, UpperTextLength, Base64 and SVG data, ImageMerged and BarcodeMerged.
- [Nested Blocks and Master-Detail Reports](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/nested-blocks/llms-full.txt): Nest merge blocks for master-detail reports in a WPF app: nested JSON, ChildBlocks in code, the block hierarchy, business objects and DataSets with relations.
- [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/overview/llms-full.txt): Plan mail merge in a WPF app: pre-shaped data, MailMerge created in code for the WPF TextControl, one document per record with DataRowMerged and printing.
- [Reporting Ribbon and WPF Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms-full.txt): The WPF RibbonReportingTab: its groups, the Field Navigation sidebar in XAML, the DocumentServer.WPF dialog windows, FieldAdapter.ShowDialog and FindName.
- [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/sorting-filtering/llms-full.txt): Filter and sort the rows of merge blocks in WPF: FilterInstruction and SortingInstruction, Apply, the WPF FilterAndSortDialog and BlockMergingCondition.
- [Formatting and Styling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/styling/llms-full.txt): Style merged WPF documents: template formatting that survives the merge, alternate row colors, TableCell and MergedField changes in FieldMerged handlers.
- [Subtemplates](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/subtemplates/llms-full.txt): Include subtemplates in WPF mail merge templates: INCLUDETEXT fields, the IncludeText class, MailMerge.SearchPath and content supplied in IncludeTextMerging.
- [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt): Plan WPF mail merge templates: sample data, inspecting the DataSourceManager of the Reporting tab, TX versus DOCX storage, layout rules and a template test.
- [Template Preview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-preview/llms-full.txt): Add a merge preview to a WPF template designer: a ToggleButton, DataSourceManager.Merge, MergeSettings, read-only EditMode and paging through records.

---

## Nearby

- **Previous:** [Content Controls](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms-full.txt)
- **Next:** [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/overview/llms-full.txt)
