TX Sheet Control

MailMergeTemplate Class

Class
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Api.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll

Immutable template. Each merge creates an independently disposable result document.

Syntax

public class MailMergeTemplate

Members

Properties

PropertyDescription
EventsFile lifecycle notifications for saves of this immutable template.

Methods

MethodDescription
MergeAsyncMerges application data into an isolated document snapshot before replacing the current workbook.
SaveAsyncSaves the captured template using the same formats and reusable options as a workbook.

Examples

Capture a reusable invoice template, merge customer data into an independent result, and export that result. Dispose each result after all awaited exports finish.

using TXTextControl.TXSheetControl.Server;

async Task<byte[]> MergeCustomerInvoiceAsync(ServerSheetControl control)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    await sheet.Cell("A1").SetTextAsync("Invoice for:");
    await sheet.Cell("A1").FormatAsync(new { fontFamily = "Liberation Sans", fontSize = 16, bold = true, textColor = "#ffffff", fillColor = "#163b63" });
    await book.SetMailMergeAsync(new { version = 1, bindings = new[] { new { sheetId = sheet.Id, cell = "B3", path = "customer.name", type = "string" } }, repeatBlocks = Array.Empty<object>() });

    var template = await book.CreateMailMergeTemplateAsync();
    await using var invoice = await template.MergeAsync(new { customer = new { name = "Alpine Design" } });
    return await invoice.Control.SaveAsync(StreamType.PDF);
}

See Also