# Mail Merge Examples

> Mail merge samples for TX Text Control .NET for Windows Forms: merge events, conditional formatting, previews, Excel and HTML in templates, and blog articles.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Examples > Mail Merge Examples
- **2637 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/mail-merge/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/mail-merge/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/mail-merge/llms-full.txt

---

[MailMerge](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/llms-full.txt) creates documents from a template and data, and its events let your code change each field, row and block while it merges. Most of the samples below are Windows Forms projects that do exactly that: they color table cells, merge cells, include Excel sheets or HTML, and preview the results record by record.

### Official Samples

The setup installs these samples, and the folder *Howto\\MailMerge* of [TXSamples\_WinForms\_CSharp](https://github.com/TextControl/TXSamples_WinForms_CSharp) contains them for version 32.0:

| Example | What it shows | Where |
|---|---|---|
| Simple merge | Merge fields filled with data | *Howto\\MailMerge\\MailMerge\_Simple* |
| Merge blocks | A section of the template repeated for each record | *Howto\\MailMerge\\MailMerge\_Blocks* |
| Nested merge blocks | Merge blocks inside merge blocks, filled from related tables | *Howto\\MailMerge\\MailMerge\_Nested\_Blocks* |

The TX Words *Reporting* sample designs templates with a sample database and merges them; see [TX Words Sample Application](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/tx-words/llms-full.txt).

### Sample Projects

All projects are Windows Forms applications in C# for the .NET Framework. The version is the one the project references today; the code dates from the year of the article.

| Example | What it shows | Where |
|---|---|---|
| Conditional cell colors | Background colors of table cells set in [FieldMerged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/fieldmerged-event/llms-full.txt) according to rules in the field names, as described in [MailMerge: Conditional Table Cell Colors using Filter Instructions](https://www.textcontrol.com/blog/2019/06/06/mailmerge-conditional-table-cell-colors-using-filter-instructions/). .NET Framework 4.5, version 34.0 | [TextControl.WindowsForms.MailMerge.ConditionalColor](https://github.com/TextControl/TextControl.WindowsForms.MailMerge.ConditionalColor) |
| Merged cells | Cells of a merge block with the same content merged vertically after [BlockRowMerged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/blockrowmerged-event/llms-full.txt), as described in [Merging Merge Block Cells Vertically with Matching Content](https://www.textcontrol.com/blog/2021/10/20/vertically-merge-table-cells-of-merge-blocks-for-matching-content/). .NET Framework 4.8, version 33.0 | [TextControl.Windows.Forms.MailMerge.MergeCells](https://github.com/TextControl/TextControl.Windows.Forms.MailMerge.MergeCells) |
| Preview with a BindingNavigator | Each record of a `BindingSource` merged into the template for a preview, as described in [Windows Forms: Preview Mail Merge Results with the BindingNavigator and a BindingSource](https://www.textcontrol.com/blog/2016/01/08/windows-forms-preview-mail-merge-results-with-the-bindingnavigator-and-a-bindingsource/). .NET Framework 4.5, version 33.0 | [TextControl.WindowsForms.MailMerge.BindingNavigator](https://github.com/TextControl/TextControl.WindowsForms.MailMerge.BindingNavigator) |
| Excel in templates | Excel sheets included through INCLUDETEXT fields in [IncludeTextMerging](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/includetextmerging-event/llms-full.txt), as described in [Merge Excel Documents into MailMerge Templates using IncludeText Fields](https://www.textcontrol.com/blog/2019/08/13/merge-excel-documents-into-mailmerge-templates/). .NET Framework 4.8, version 34.0 | [TextControl.WindowsForms.MailMergeExcel](https://github.com/TextControl/TextControl.WindowsForms.MailMergeExcel) |
| Formatted HTML | HTML from the data merged into merge fields with its formatting, as described in [Reporting: Merge Formatted HTML into Merge Fields](https://www.textcontrol.com/blog/2014/02/10/reporting-merge-formatted-html-into-merge-fields/). .NET Framework 4.0, version 34.0 | [TextControl.MailMerge.MergeFormattedHTML](https://github.com/TextControl/TextControl.MailMerge.MergeFormattedHTML) |
| DOCVARIABLE fields | DOCVARIABLE fields of MS Word documents converted into merge fields before the merge, as described in [Reporting: Merging MS Word Documents with DocVariables](https://www.textcontrol.com/blog/2015/06/10/reporting-merging-ms-word-documents-with-docvariables/). .NET Framework 4.8, version 34.0 | [TextControl.MailMerge.DocVariables](https://github.com/TextControl/TextControl.MailMerge.DocVariables) |
| Sums in merge blocks | Custom SUM fields totaled for each merge block, as described in [MailMerge: Dynamic, Custom SUM Fields in Merge Blocks](https://www.textcontrol.com/blog/2014/06/18/mailmerge-dynamic-custom-sum-fields-in-merge-blocks/). .NET Framework 4.0, version 34.0 | [TextControl.MailMerge.CustomSUMFields](https://github.com/TextControl/TextControl.MailMerge.CustomSUMFields) |
| Conditional sub-templates | INCLUDETEXT fields included or skipped for each record, as described in [MailMerge: Conditional INCLUDETEXT Fields](https://www.textcontrol.com/blog/2015/01/08/mailmerge-conditional-includetext-fields/). .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.ConditionalIncludeFields](https://github.com/TextControl/TextControl.MailMerge.ConditionalIncludeFields) |
| Events for custom processing | Fields, rows and block rows processed in the merge events, as described in [Reporting: Custom Processing Using MailMerge Events](https://www.textcontrol.com/blog/2014/05/07/reporting-custom-processing-using-mailmerge-events/). .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.CustomProcessingWithEvents](https://github.com/TextControl/TextControl.MailMerge.CustomProcessingWithEvents) |
| Empty lines | Lines of an address removed when all their fields are empty, as described in [Mail Merge: Suppress Lines with Empty Merge Fields](https://www.textcontrol.com/blog/2014/08/01/mail-merge-suppress-lines-with-empty-merge-fields/). .NET Framework 4.5, version 33.0 | [TextControl.MailMerge.Suppress-Lines-With-Empty-Merge-Fields](https://github.com/TextControl/TextControl.MailMerge.Suppress-Lines-With-Empty-Merge-Fields) |
| Line breaks in the data | Line breaks in field values turned into line breaks of the document, as described in [MailMerge: MergeFields with CRLFs](https://www.textcontrol.com/blog/2015/09/02/mailmerge-mergefields-with-crlfs/). .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.CRLF](https://github.com/TextControl/TextControl.MailMerge.CRLF) |
| Remapping merge fields | A dialog that maps the field names of a template to the columns of new data, as described in [Dialog Project: Remapping Merge Fields](https://www.textcontrol.com/blog/2015/09/17/dialog-project-remapping-merge-fields/). .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.FieldRemapping](https://github.com/TextControl/TextControl.MailMerge.FieldRemapping) |
| Conditional text blocks | Formatted text, tables and images between two marker fields of the template kept or removed for each record in [DataRowMerged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/datarowmerged-event/llms-full.txt), as described in [Reporting: Conditional Formatted Text Blocks](https://www.textcontrol.com/blog/2015/03/13/reporting-conditional-formatted-text-blocks/). .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.ConditionalTextBlock](https://github.com/TextControl/TextControl.MailMerge.ConditionalTextBlock) |
| Check boxes from data | MS Word check box form fields checked from Boolean values of the data with the [FormCheckBox](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver-fields/formcheckbox/llms-full.txt) field adapter, as described in [MailMerge: Merge CheckBoxes During the Merge Process](https://www.textcontrol.com/blog/2015/01/12/mailmerge-merge-checkboxes-during-the-merge-process/). .NET Framework 4.5, version 33.0 | [TextControl.MailMerge.CheckBoxes](https://github.com/TextControl/TextControl.MailMerge.CheckBoxes) |
| Empty table rows | Alternating row colors from NEXT fields, and empty rows at the end of a merge block removed in [BlockRowMerged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/blockrowmerged-event/llms-full.txt), as described in [Reporting: Removing Empty Table Rows](https://www.textcontrol.com/blog/2014/09/30/reporting-removing-empty-table-rows/). .NET Framework 4.5, version 33.0 | [TextControl.MailMerge.RemoveEmptyTableRows](https://github.com/TextControl/TextControl.MailMerge.RemoveEmptyTableRows) |
| Business objects | Collections of business objects merged into merge blocks and nested merge blocks, with totals calculated in the objects instead of the template, as described in [Advantages of Using Business Objects with Text Control Reporting](https://www.textcontrol.com/blog/2014/05/02/advantages-of-using-business-objects-with-text-control-reporting/). .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.BusinessObjectsUsage](https://github.com/TextControl/TextControl.MailMerge.BusinessObjectsUsage) |
| Progress bar | A progress bar advanced in `DataRowMerged` for each merged record, as described in [Reporting: Updating a Progress Bar During Merge Processes](https://www.textcontrol.com/blog/2014/03/26/reporting-updating-a-progress-bar-during-merge-processes/). .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.ProgressBar](https://github.com/TextControl/TextControl.MailMerge.ProgressBar) |
| Images from files | Image placeholders merged from file names in the data, with the folder of the images set in [SearchPath](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/searchpath-property/llms-full.txt), as described in [Reporting: Merging Images from Files Using SearchPath](https://www.textcontrol.com/blog/2014/03/12/reporting-merging-images-from-files-using-searchpath/). .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.MergeImagesFromFiles](https://github.com/TextControl/TextControl.MailMerge.MergeImagesFromFiles) |
| Shipping labels | A label template with two page columns filled with one label per record, as described in [MailMerge: Creating Shipping Labels Using TX Text Control](https://www.textcontrol.com/blog/2012/11/23/mailmerge-creating-shipping-labels-using-tx-text-control/). .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.ShippingLabels](https://github.com/TextControl/TextControl.MailMerge.ShippingLabels) |

### Blog Articles With Code

These articles use `MailMerge` with a `ServerTextControl`; the class is the same in TX Text Control .NET for Windows Forms, where the `TextControl` of a form can also be its template:

| Example | What it shows | Where |
|---|---|---|
| Overview | Templates, data sources, merge blocks and the events of `MailMerge` | [An Ultimate Guide to Mail Merge with MS Word Documents in C#](https://www.textcontrol.com/blog/2023/06/07/an-ultimate-guide-to-mail-merge-with-ms-word-documents-in-csharp/) |
| Sorting and filtering | The rows of merge blocks sorted and filtered | [Filtering and Sorting Repeating Blocks in MailMerge using C#](https://www.textcontrol.com/blog/2025/08/21/filtering-and-sorting-repeating-blocks-in-mailmerge-using-csharp/) |
| Calculating business objects | Business objects that calculate their own totals, merged into a template | [Merging Self-Calculating Business Objects with TX Text Control MailMerge in C#](https://www.textcontrol.com/blog/2024/12/27/merging-self-calculating-business-objects-with-tx-text-control-mailmerge-in-csharp/) |
| Table cells | Table cells changed while the merge runs | [Manipulating Table Cells During the MailMerge Process in .NET C#](https://www.textcontrol.com/blog/2024/12/03/manipulating-table-cells-during-the-mailmerge-process-in-net-csharp/) |
| Merge blocks in code | Merge blocks inserted with the [DataSourceManager](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver-datasources/datasourcemanager/llms-full.txt) | [Mail Merge: Inserting Merge Blocks using the DataSourceManager in C#](https://www.textcontrol.com/blog/2024/10/02/mail-merge-inserting-merge-blocks-using-the-datasourcemanager-in-csharp/) |
| Hyperlinks | Hyperlinks created from the data in `FieldMerged` | [MailMerge: Merging Hyperlinks using the FieldMerged Event](https://www.textcontrol.com/blog/2022/06/08/mailmerge-merging-hyperlinks-using-the-fieldmerged-event/) |

### Next Steps

- [Mail Merge and Reporting](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/llms-full.txt): templates, data sources and merge blocks, explained.
- [Mail Merge](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/mail-merge/llms-full.txt) in Getting Started: merge a first template step by step.
- [PDF Examples](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/pdf/llms-full.txt): merged documents saved as PDF and electronic invoices.

---

## Nearby

- **Previous:** [Document Processing Examples](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/document-processing/llms-full.txt)
- **Next:** [PDF Examples](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/examples/pdf/llms-full.txt)
