Interactive editor
Explore Mail Merge Overview
Design Word-compatible templates and merge them with data using the reporting engine.
Use Reporting > Preview to merge it with the nested JSON data source.
Understand the current template
Explore its merge fields, repeating blocks, and nested structure in an interactive template map.
How mail merge works
Template
INVOICE
«SalesOrderNumber»
«Customer_Customer.Name»
«Production_Product.Name»
«TotalDue»
+
JSON data
{
"SalesOrderNumber": "SO43660",
"Customer_Customer": {
"Name": "Sports Sales and Rental"
},
"TotalDue": 1716.18
}
=
Result
INVOICE
SO43660
Sports Sales and Rental
Road-650 Red, 44
$1,716.18
Ready to tryUse the controls above to interact with this demo.
What this demonstrates
Mail Merge Overview
This sample connects a pre-designed invoice template to a hierarchical JSON data source. The editor uses that data immediately for field selection and browser-based merge previews.
Key members
Designer data
TextControl.LoadDataFromJson
Server-side merge
MailMerge.MergeJsonData
How it works
1. Load the template and its design data
LoadText opens the invoice template. Chaining LoadDataFromJson supplies the Reporting ribbon with the available fields and lets Reporting > Preview merge the document directly in the browser.
<div class="tx-editor-host">
@Html.TXTextControl().TextControl(settings => {
settings.Dock = DockStyle.Fill;
})
.LoadText(templatePath, StreamType.InternalUnicodeFormat)
.LoadDataFromJson(System.IO.File.ReadAllText(dataPath))
.Render()
</div>
2. Preserve the hierarchy in JSON
Nested objects become dot-notation merge fields, such as Customer_Customer.Name. Arrays become repeating merge blocks, so every item in Sales_SalesOrderDetail can produce a table row.
{
"Customer_Customer": {
"Name": "Sports Sales and Rental"
},
"Sales_SalesOrderDetail": [
{
"OrderQty": 1,
"Production_Product": {
"Name": "Road-650 Red, 44"
}
}
]
}
3. Generate final documents on the server
The designer and the production merge can share the same template and JSON. For automated generation, assign a ServerTextControl to MailMerge, load the template, and pass the unchanged JSON to MergeJsonData.
using var textControl = new ServerTextControl();
textControl.Create();
using var mailMerge = new MailMerge {
TextComponent = textControl
};
mailMerge.LoadTemplate(templatePath, FileFormat.InternalUnicodeFormat);
mailMerge.MergeJsonData(json);