TX Text Control .NET for WPF

Mail Merge Examples

Topic

MailMerge creates documents such as invoices, letters and reports from a template and data. In a WPF application, the template can be the document of the TextControl in your window: the WPF samples assign the control to TextComponent. The official samples show the basics, and further samples written for Windows Forms or TX Text Control .NET Server show techniques with the same MailMerge class.

WPF Samples

The setup installs these samples, and TXSamples_WPF_CSharp and TXSamples_WPF_VB.NET contain them for version 32.0, for the .NET Framework 4.8 and .NET 6:

ExampleWhat it showsWhere
Simple mergeMerge fields inserted from menu items built from the columns of an XML data set, then filled with MergeTXSamples_WPF_CSharp, folder Howto\MailMerge\MailMerge_Simple
Merge blocksA DOCX template with a merge block, a section repeated for each record, filled with the orders of a data setTXSamples_WPF_CSharp, folder Howto\MailMerge\MailMerge_Blocks
Nested merge blocksA report with blocks inside blocks, filled from related tables, and a progress bar updated in BlockRowMergedTXSamples_WPF_CSharp, folder Howto\MailMerge\MailMerge_Nested_Blocks
TX Words ReportingTemplates for an invoice, a packing list and a shipping label, designed with a sample database in the reporting tab of the ribbon and merged with the DataSourceManager that RibbonReportingTab.DataSourceManager returnsTXSamples_WPF_CSharp, folder TX Words

The export dialog of the Reporting sample on GitHub saves DOCX files with StreamType.SpreadsheetML, the Excel format; for DOCX, use StreamType.WordprocessingML.

Other Samples

These samples were written for other products. Their MailMerge code is the same in WPF; replace a Windows Forms TextControl with the WPF TextControl or a ServerTextControl:

ExampleWhat it showsWhere
Dynamic contractsSections of a contract template included or left out according to JSON data, as described in Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET. A console application for TX Text Control .NET Server, .NET 8, version 33.0TXTextControl.Server.NDA.Dynamic
Mustache placeholdersA class that turns {{placeholders}} into merge fields and merge blocks, as described in Mail Merge: Merging Templates with Mustache Syntax in C#. A class without a projectMustacheMatcher
Parallel mergingDocuments merged in separate processes at the same time, as described in True Parallel Processing of Documents using MailMerge, which says the concept applies to WPF as well. Windows Forms, .NET Framework 4.8, version 30.0TextControl.WindowsForms.Parallel
DOCVARIABLE fieldsDOCVARIABLE fields of MS Word documents converted into merge fields, as described in Reporting: Merging MS Word Documents with DocVariables. Windows Forms, .NET Framework 4.8, version 34.0TextControl.MailMerge.DocVariables
Formatted HTMLHTML from the data merged into merge fields with its formatting, as described in Reporting: Merge Formatted HTML into Merge Fields. Windows Forms, .NET Framework 4.0, version 34.0TextControl.MailMerge.MergeFormattedHTML
Events for custom processingFields, rows and block rows processed in the merge events, as described in Reporting: Custom Processing Using MailMerge Events. Windows Forms, .NET Framework 4.0, version 33.0TextControl.MailMerge.CustomProcessingWithEvents
Business objectsCollections 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. Windows Forms, .NET Framework 4.8, version 33.0TextControl.MailMerge.BusinessObjectsUsage
Images from filesImage placeholders merged from file names in the data, with the folder of the images set in SearchPath, as described in Reporting: Merging Images from Files Using SearchPath. Windows Forms, .NET Framework 4.0, version 33.0TextControl.MailMerge.MergeImagesFromFiles
Empty table rowsAlternating row colors from NEXT fields, and empty rows at the end of a merge block removed in BlockRowMerged, as described in Reporting: Removing Empty Table Rows. Windows Forms, .NET Framework 4.5, version 33.0TextControl.MailMerge.RemoveEmptyTableRows

Blog Articles With Code

ExampleWhat it showsWhere
Sorting and filteringThe rows of merge blocks sorted and filteredFiltering and Sorting Repeating Blocks in MailMerge using C#
Calculating business objectsBusiness objects that calculate their own totals, merged into a templateMerging Self-Calculating Business Objects with TX Text Control MailMerge in C#
Merge blocks in codeMerge blocks inserted with the DataSourceManagerMail Merge: Inserting Merge Blocks using the DataSourceManager in C#

Next Steps