# Mail Merge and Reporting

> Create documents from templates and data with MailMerge: data sources, merge fields and blocks, conditional content, images, barcodes and template design.

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

---

Hundreds of invoices from one layout, a contract with only the clauses a customer needs, a report whose tables grow with its data: `MailMerge` produces them by merging templates with data. Going beyond a first merge means knowing the shapes of data and the options of fields and blocks, and building conditional content, images, barcodes and templates that hold up with real data.

If you haven't merged a template yet, start with [Getting Started: Mail Merge](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/mail-merge/llms-full.txt). The [MailMerge](https://docs.textcontrol.com/tx-text-control-dotnet-server/overview/components/mailmerge/llms-full.txt) page in the Overview explains the class and where it runs.

### How Mail Merge Works

A merge brings three parts together:

- **The template** is a document designed in MS Word, in the Document Editor or in code. It contains merge fields for single values, merge blocks for repeating and optional sections, and placeholders for images and barcodes.
- **The data** is prepared in the structure the document needs, as JSON, business objects or a `DataSet`. Its names match the names of the fields and blocks.
- **`MailMerge`** fills the template held by a `ServerTextControl` with the data. The result is saved as PDF, DOCX or another format, as one document or as one document per record.

Formatting, layout and rules such as filters stay in the template, so the merge code doesn't change when a designer changes them.

### Find the Right Page

| If you want to | Read |
|---|---|
| Understand the reporting model, create separate documents per record, follow a merge with events or merge in a Web API | [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/overview/llms-full.txt) |
| Merge JSON, business objects, dictionaries or a `DataSet`, or load the same data into the Document Editor | [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/data-sources/llms-full.txt) |
| Format numbers and dates, insert date fields, change merged fields in code or merge form fields | [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/fields/llms-full.txt) |
| Repeat rows and sections for each record, or build master-detail reports | [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/blocks/llms-full.txt), [Nested Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/nested-blocks/llms-full.txt) |
| Merge logos, photos and QR codes | [Images](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/images/llms-full.txt), [Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/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-server/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-server/mail-merge/sorting-filtering/llms-full.txt) |
| Color rows, highlight values or calculate totals in merged tables | [Styling](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/styling/llms-full.txt) |
| Design, store and test templates that merge well | [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/template-design/llms-full.txt) |
| Try fields, blocks and rules step by step in an online demo | [Template Assistant](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/template-assistant/llms-full.txt) |

### Where to Start

1. [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/overview/llms-full.txt): how templates, data and the merge work together.
2. [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/data-sources/llms-full.txt): the data your application merges.
3. [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/fields/llms-full.txt) and [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/blocks/llms-full.txt): the elements of every template.
4. [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/template-design/llms-full.txt): templates that work with real data.

### Related Sections

- [Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-editor/llms-full.txt): let users design templates in the browser.
- [Document Processing](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/llms-full.txt): change merged documents with `ServerTextControl`.
- [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/llms-full.txt): create PDF/A documents and forms from merged documents.
- [Performance and Scalability](https://docs.textcontrol.com/tx-text-control-dotnet-server/performance/llms-full.txt): merge large numbers of documents.

---

## In This Section

- [Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/barcodes/llms-full.txt): Merge data into barcodes: named barcode placeholders, QR codes and 1D and 2D types, TXBarcodeCore, UpperTextLength, BarcodeMerged and value validation.
- [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/blocks/llms-full.txt): Merge blocks in depth: content, DOCX storage, paragraph and table row blocks with InsertMergeBlock, single objects, GetBlockNames, block events and DataSets.
- [Conditional Content](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/conditional-content/llms-full.txt): Include or leave out content depending on the data: IF and NEXTIF fields, optional sections as merge blocks, block conditions, sub-templates and FieldMerged.
- [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/data-sources/llms-full.txt): Merge JSON, business objects, DataSets and XML with MailMerge: ParserException, parsing cultures, IDataRowAdapter records in events and where .rdsc files apply.
- [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/fields/llms-full.txt): Format merge fields with the MergeField class: number and date formats in all text parts, DATE fields, FieldMerged, HTML values, kept fields and form fields.
- [Images](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/images/llms-full.txt): Merge images into templates: named image placeholders, Base64 data, files and SVG, RemoveEmptyImages, the ImageMerged event and image merge fields.
- [Nested Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/nested-blocks/llms-full.txt): Build master-detail reports with nested merge blocks: nested JSON and objects, DataSets with relations, templates created with ChildBlocks and empty levels.
- [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/overview/llms-full.txt): Reporting model of MailMerge: flow layout templates, pre-shaped data, merged elements, one document per record with DataRowMerged, skipped records and events.
- [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/sorting-filtering/llms-full.txt): Sort and filter merge block rows: the Filter and Sort dialog of the Document Editor, FilterInstruction, SortingInstruction, BlockMergingCondition and Apply.
- [Styling](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/styling/llms-full.txt): Style merged documents: formatting kept from templates, alternating row colors, cells and text formatted by value, number formats, formulas and page format.
- [Template Assistant](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/template-assistant/llms-full.txt): Try the Mail Merge Template Assistant online demo: steps from JSON data to outline, how browser and server share the work, and the APIs it is built on.
- [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/template-design/llms-full.txt): Design templates that merge well: MS Word or the Document Editor, sample data, TX or DOCX storage, layout rules, sub-templates and testing a template.

---

## Nearby

- **Previous:** [Server Visualization](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-processing/server-visualization/llms-full.txt)
- **Next:** [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-server/mail-merge/overview/llms-full.txt)
