TX Sheet Control

Workbook.SetMailMergeAsync Method

Method
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server as TXTextControl.TXSheetControl.Api.dll from the private NuGet feed or the supplied NuGet folder
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll

Syntax

public Task SetMailMergeAsync(object? metadata, CancellationToken cancellationToken = default)

Parameters

ParameterTypeOptionalDescription
metadataobject?NoValue matching metadata's declared type and the owning object's validation rules.
cancellationTokenCancellationTokenYesCancels waiting or execution as supported by this operation.

Return Value

Task.

Examples

Bind the customer name to a real worksheet cell, merge a customer record and return the resulting invoice PDF.

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 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);
}

Remarks

Use the member with an instance or settings object from the documented package. Await task-returning operations. Document-bound handles must be resolved again after loading or deleting their owner.

See Also