MailMergeTemplate.SaveAsync Method
- Namespace
TXTextControl.TXSheetControl. Server
- Package
TXTextControl.asTXSheetControl. Server TXTextControl.from the private NuGet feed or the supplied NuGet folderTXSheetControl. Api. dll
- Also in
TXTextControl.asTXSheetControl. Blazor TXTextControl.TXSheetControl. Api. dll
Saves the captured template using the same formats and reusable options as a workbook.
Syntax
Overload 1
public Task<byte[]> SaveAsync(StreamType streamType, SaveOptions? options = null, CancellationToken cancellationToken = default)
| Parameter | Type | Optional | Description |
|---|---|---|---|
streamType | StreamType | No | The supported input or output format. PDF is output-only. |
options | SaveOptions? | Yes | Supported settings for this operation; omitted settings retain documented defaults. |
cancellationToken | CancellationToken | Yes | Cancels waiting or execution as supported by this operation. |
Return value: Task<byte[]>.
Overload 2
public Task SaveAsync(string fileName, StreamType streamType, SaveOptions? options = null, CancellationToken cancellationToken = default)
| Parameter | Type | Optional | Description |
|---|---|---|---|
fileName | string | No | Application-authorized input or output file path. |
streamType | StreamType | No | The supported input or output format. PDF is output-only. |
options | SaveOptions? | Yes | Supported settings for this operation; omitted settings retain documented defaults. |
cancellationToken | CancellationToken | Yes | Cancels waiting or execution as supported by this operation. |
Return value: Task.
Overload 3
public Task SaveAsync(Stream stream, StreamType streamType, SaveOptions? options = null, CancellationToken cancellationToken = default)
| Parameter | Type | Optional | Description |
|---|---|---|---|
stream | Stream | No | Value matching stream's declared type and the owning object's validation rules. |
streamType | StreamType | No | The supported input or output format. PDF is output-only. |
options | SaveOptions? | Yes | Supported settings for this operation; omitted settings retain documented defaults. |
cancellationToken | CancellationToken | Yes | Cancels waiting or execution as supported by this operation. |
Return value: Task.
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();
return await template.SaveAsync(StreamType.InternalWorkbookFormat);
}
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.