# Blazor

> Build Blazor Server and WebAssembly spreadsheet editors with typed C# workbook operations, store-issued licensing, file streams and component events.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Getting Started > Spreadsheet Editor > Blazor
- **2291 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/blazor/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/blazor/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/blazor/llms-full.txt

---

The `TXTextControl.TXSheetControl.Blazor` NuGet package adds the browser spreadsheet editor to Blazor Server and WebAssembly on .NET 10, with typed C# workbook APIs and completed notifications.

### Install the Package

Install the package from the Text Control Private NuGet Feed with the `nuget.config` from your assignment email, as [Install the NuGet Packages](https://docs.textcontrol.com/tx-sheet-control/installation/nuget/llms-full.txt) describes. Without the feed, add the `nuget` folder of the download as another source and keep nuget.org enabled:

```bash
dotnet nuget add source /path/to/TX-Sheet-Control-2.0/nuget --name TXSheetControl

dotnet new blazor -n SheetServer --interactivity Server
dotnet add SheetServer/SheetServer.csproj package TXTextControl.TXSheetControl.Blazor --version 2.0.0
```

For standalone WebAssembly:

```bash
dotnet new blazorwasm -n SheetClient
dotnet add SheetClient/SheetClient.csproj package TXTextControl.TXSheetControl.Blazor --version 2.0.0
```

The package includes protected JavaScript, Shadow DOM styles, fonts, language files and the portable C# document API. It does not require the native Server package.

### Configure Licensing

Download `tx-sheet-control.license` with the **License** button of the email that you receive when a serial number is assigned to you, and pass its contents unchanged to `SheetControlOptions.License`. Set `TXSheetControl:License` in application configuration. WebAssembly can read this from `wwwroot/appsettings.json`. Browser configuration is public. Keep store issuer secrets out of it. The existing store-issued browser reader verifies the license before `Ready`. Trial, Developer and OEM licensing and watermark rules match the other editor integrations.

### Add a Worksheet

Add this component to an interactive page. In Blazor Server, add `@rendermode InteractiveServer` above the markup. Standalone WebAssembly needs no render-mode directive.

```cshtml
@using TXTextControl.TXSheetControl.Blazor
@using TXTextControl.TXSheetControl.Server
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
<TXSheetControl Options="options" Ready="OnReady" Error="OnError" Height="640" />
<p role="status">@status</p>
@code {
    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}";
}
```

Wait for `Ready` before using the API. Prerendering emits the host element, and initialization starts after interactive rendering. Shared `Workbook`, `Worksheet`, `Cell` and `Range` types remain in `TXTextControl.TXSheetControl.Server` when used by Blazor.

### Load and Save

Keep the control received by `Ready` in a field. Import `Microsoft.AspNetCore.Components.Forms` and connect `<InputFile OnChange="OpenFile" />` to this handler:

```csharp
private BlazorSheetControl control = default!;
private async Task OpenFile(InputFileChangeEventArgs args)
{
    await using var stream = args.File.OpenReadStream(128L * 1024 * 1024);
    await control.LoadAsync(stream, StreamType.SpreadsheetML);
}
private Task<byte[]> ExportPdf() => control.SaveAsync(StreamType.PDF);
```

Use exported bytes for a download or an application API request. Binary transfers are bounded to 128 MiB, and caller-owned streams remain open. Filesystem-name overloads throw `PlatformNotSupportedException`.

### Events and Lifetime

The component exposes `Changed`, `Edited`, `Loaded`, `Saved`, `Event` and `SelectionChanged` callbacks. `Error` handles initialization and callback failures. Awaited API calls also throw `ServerSheetControlException` with a machine-readable `Code` and need their own error handling.

Completed events arrive asynchronously and cannot cancel committed edits. Configure validation rules before editing. Synchronous before-events and synchronous C# cell-renderer callbacks are unavailable in the browser host.

The component owns and disposes its control when removed from the render tree. Dispose independent mail-merge result controls before their parent. Loading a replacement workbook invalidates previously acquired worksheet, cell and range handles.

### Update Options

Assign a new options record to change theme, language, zoom, author, ribbon policies, resource overrides, view mode, chrome visibility or dependent highlighting:

```csharp
options = options with
{
    Theme = "dark", Language = "de", Zoom = 125,
    Ribbon = new() { Layout = "compact", DisplayMode = "expanded" }
};
```

License, initial capacities, growth limits, dashboard policy, locale and font URLs are mount settings. Change `@key` to recreate the component when changing these settings. Omitted ribbon, resource and author patches preserve current values.

### Custom Calculation

Register C# custom functions through `Workbook.Calculation.RegisterFunctionAsync`. Browser evaluation calls C# asynchronously. Keep callbacks short, observe their cancellation token and return the calculated value. Calling back into the same control from its formula callback is rejected to prevent interop deadlock.

### Backend Processing

Blazor Server still runs the editor engine in the browser. Install the native Server package separately for independent backend jobs. Exchange TXWB or XLSX bytes explicitly. The browser and backend controls do not share live workbook state.

### See Also

- [Install the NuGet Packages](https://docs.textcontrol.com/tx-sheet-control/installation/nuget/llms-full.txt).
- [Blazor Deployment](https://docs.textcontrol.com/tx-sheet-control/deployment/blazor/llms-full.txt).
- [Blazor API](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-blazor/llms-full.txt).
- [Licensing](https://docs.textcontrol.com/tx-sheet-control/deployment/licensing/llms-full.txt).

---

## Nearby

- **Previous:** [Angular](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/angular/llms-full.txt)
- **Next:** [Document Processing](https://docs.textcontrol.com/tx-sheet-control/getting-started/document-processing/llms-full.txt)
