TX Sheet Control

IDataSource Interface

Interface
Namespace
TXTextControl.TXSheetControl.Data
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Data.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Implemented by
HttpDataSource

Server-owned asynchronous query. Implementations own authorization, credentials and query definitions. Registered instances must support concurrent requests; returned snapshots are immutable.

Syntax

public interface IDataSource

Members

Properties

PropertyDescription
CapabilitiesDescribes supported request operations.

Methods

MethodDescription
QueryAsyncReturns no more than request.Limit rows. Cancellation must cover opening, reading and disposal.

Examples

Request a bounded snapshot from an application-provided data source, honor its paging capability and write the returned columns and rows into a report.

using TXTextControl.TXSheetControl.Data;
using TXTextControl.TXSheetControl.Server;

async Task<byte[]> ExportProviderDataAsync(ServerSheetControl control, IDataSource source)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    var request = new DataRequest { Limit = 100 };

    if (!source.Capabilities.HasFlag(DataSourceCapabilities.Paging)) request = new DataRequest();

    var data = await source.QueryAsync(request);

    if (data.Rows.Count == 0) return await control.SaveAsync(StreamType.PDF);

    var lastColumn = "";

    for (var index = data.Columns.Count; index > 0; index /= 26) { index--; lastColumn = (char)(65 + index % 26) + lastColumn; }

    await sheet.Range("A1:" + lastColumn + "1").SetValuesAsync([data.Columns.Cast<object?>().ToArray()]);
    await sheet.Range("A2:" + lastColumn + (data.Rows.Count + 1)).SetValuesAsync(data.Rows.Select(row => row.ToArray()).ToArray());
    return await control.SaveAsync(StreamType.PDF);
}

See Also