TX Sheet Control

WorkbookDataBinding Class

Class
Namespace
TXTextControl.TXSheetControl.Data
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Server.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Implements
IDisposable

Optional bridge for one workbook lifetime. Fetch completes before mutation; latest refresh wins per target. Loading cancels pending refreshes. Host owns authorization and scheduling; dispose when the host is destroyed.

Syntax

public class WorkbookDataBinding

Interfaces: IDisposable.

Members

Constructors

ConstructorDescription
ConstructorCreates a bridge for one workbook. Registry and workbook ownership remain with the application.

Methods

MethodDescription
DisposeCancels all in-flight refreshes and releases event subscriptions. Existing cell/snapshot values remain.
RefreshDashboardAsyncRefreshes a direct dashboard source with no worksheet. Persists only logical IDs and name. Source registration and transient replacement share one workbook batch. Failures retain previous data.
RefreshRangeAsyncReplaces a fixed owned rectangle, optionally including column headers. Usable for a whole table range. Column count must match; excess rows fail before writing. Unused trailing rows are cleared to prevent stale totals. Formulas outside the rectangle are preserved. Table structure/size is retained. Target must belong to this workbook.

Examples

Create a working report from bounded HTTP sales data. Supply an application-owned HttpClient and service URL; scope cached data to its actual audience.

using System.Net.Http;
using TXTextControl.TXSheetControl.Data;
using TXTextControl.TXSheetControl.Server;

async Task<byte[]> BuildWorkbookDataBindingExampleAsync(ServerSheetControl control, HttpClient client, Uri serviceBase)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    var source = new HttpDataSource(client, request => new HttpRequestMessage(HttpMethod.Get, new Uri(serviceBase, "sales?offset=" + request.Offset + "&limit=" + request.Limit)), ["Region", "Revenue"]);
    var registry = new DataSourceRegistry();
    registry.Register("sales-service", "regional-sales", source);

    var request = new DataRequest { Offset = 0, Limit = 100, Parameters = new Dictionary<string, object?> { ["year"] = 2026 } };
    var options = new DataQueryOptions { Timeout = TimeSpan.FromSeconds(15), CacheDuration = TimeSpan.FromMinutes(1), CacheScope = "public-regional-sales" };
    using var binding = new WorkbookDataBinding(book, registry);
    await binding.RefreshRangeAsync(sheet.Range("A1:B101"), "sales-service", "regional-sales", request, options);
    await sheet.Range("A1:B1").FormatAsync(new { fontFamily = "Liberation Sans", fontSize = 16, bold = true, textColor = "#ffffff", fillColor = "#163b63" });
    return await control.SaveAsync(StreamType.PDF);
}

See Also