TX Sheet Control

TXSheetControl Class

Class
Namespace
TXTextControl.TXSheetControl.Blazor
Package
TXTextControl.TXSheetControl.Blazor from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Blazor.dll
Install
dotnet add package TXTextControl.TXSheetControl.Blazor .NET 10 and later.
Inherits
  1. ComponentBase
  2. TXSheetControl
Implements
IAsyncDisposable

Razor component that owns a browser spreadsheet editor and provides typed lifecycle, workbook and selection callbacks.

Syntax

public class TXSheetControl

Members

MemberDescription
ConstructorCreates TXSheetControl settings or event data for the component.
ChangedCompleted workbook transactions with worksheet and address context.
ClassOptional CSS class on the Blazor-owned host.
ControlTyped browser document host, available after Ready. It has the same Workbook API as ServerSheetControl.
DisposeAsyncReleases this editor and module reference when its component leaves the render tree.
EditedCompleted cell edits; asynchronous handlers cannot cancel committed edits.
ErrorInitialization and event-handler failures. Invoked API methods also report failures by throwing.
EventAll forwarded completed workbook notifications and file progress.
HeightEditor host height in CSS pixels, from 100 through 10000.
LoadedSuccessful document replacement, including detached conversion warnings.
OptionsRequired browser settings. License and worksheet capacities apply when the component is first mounted.
ReadyRaised after browser license verification, font discovery and editor initialization.
SavedSuccessful document export.
SelectionChangedDetached screen selection changes.
StyleAdditional host CSS declarations. Editor styles remain in Shadow DOM.

Examples

@using TXTextControl.TXSheetControl.Blazor
@using TXTextControl.TXSheetControl.Server
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
<TXSheetControl Options="options" Ready="OnReady" Error="OnError" Height="640" Class="sheet-editor" Style="width:100%" @ref="component"
    Changed="OnNotification" Edited="OnNotification" Loaded="OnNotification"
    Saved="OnNotification" Event="OnNotification" SelectionChanged="OnSelection" />
<p role="status">@status</p>
@code {
    private TXSheetControl? component;
    private void OnNotification(WorkbookEventArgs args) { status = "Workbook updated"; }
    private void OnSelection(SelectionChangedEventArgs args) { status = $"{args.Active} on {args.SheetId}"; }
    private SheetControlOptions options = default!;
    private string status = "Initializing";
    protected override void OnInitialized() => options = new()
    { License = Configuration["TXSheetControl:License"] ?? "", Rows = 2000, Columns = 20 };
    private async Task OnReady(BlazorSheetControl control)
    {
        var sheet = await control.Workbook.Sheets.AtAsync(0);
        await sheet.Range("A1:D2").SetValuesAsync([
            ["Item", "Quantity", "Price", "Total"], ["Notebook", 5, 12, null]
        ]);
        await sheet.Cell("D2").SetFormulaAsync("=B2*C2");
        await sheet.Range("A1:D1").FormatAsync(new { font = new { bold = true } });
        status = $"Ready ({(await control.GetLicenseInfoAsync()).Type})";
    }
    private void OnError(SheetControlErrorEventArgs error) =>
        status = $"{error.Code}: {error.Message}";
}

Remarks

Use the component only after interactive rendering. Browser document operations execute in the editor through JavaScript interop. Completed notifications cannot synchronously cancel edits.

See Also