Getting Started with TX Sheet Control in Blazor WebAssembly
Build your first Blazor WebAssembly spreadsheet application with TX Sheet Control. Configure the license, editor areas, and ribbon, load workbooks and CSV data, and edit cell text, values, and formulas using C#. Includes a complete sample.

TX Sheet Control brings a spreadsheet editor to Blazor WebAssembly with a Razor component and a typed C# workbook API. In this tutorial, we configure the license, editor areas, and ribbon, load XLSX documents and CSV data, and change cell text, values, and formulas from C#.
The application uses a standalone .NET 10 Blazor WebAssembly project. Its C# component code runs in the browser on the WebAssembly runtime, alongside the spreadsheet editor. The sample does not need a Blazor Server circuit or a workbook-processing service. The sample uses TX Sheet Control 2.0.0.
Create the Blazor WebAssembly Application
Install the .NET 10 SDK or use Visual Studio 2026. Configure the Text Control private NuGet feed with the supplied nuget.config, keeping nuget.org enabled for the framework dependencies. You can also use the NuGet folder from the TX Sheet Control download.
dotnet new blazorwasm -n TXSheetControlBlazorWebAssemblyGettingStarted -f net10.0 --empty
cd TXSheetControlBlazorWebAssemblyGettingStarted
dotnet add package TXTextControl.TXSheetControl.Blazor --version 2.0.0
The package includes the browser editor, styles, fonts, language resources, and portable C# workbook types. The editor works independently of TXTextControl.TXSheetControl.Server; installing the native server processing package is not required for this sample.
Configure the Application
The standalone template registers the root component and HeadOutlet. Its scoped HttpClient uses the application base address, so the license and workbook URLs remain relative to the application. Keep the template wwwroot/index.html and its WebAssembly bootstrap script.
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using TXSheetControlBlazorWebAssemblyGettingStarted;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
The component imports its packaged JavaScript module after interactive rendering and installs its styles inside its Shadow DOM. Keep the generated Blazor host scripts; no manual script or stylesheet references to the spreadsheet package are needed.
Create an Instance with Options
Copy the complete contents of your tx-sheet-control.license into wwwroot/tx-sheet-control-license.txt. The page loads this text with Http.GetStringAsync before rendering the editor. The .txt extension lets a static host serve the file without a custom MIME mapping. The signed browser license is public application content; keep backend credentials and issuer secrets on the server.
Open Pages/Home.razor. The following page defines the editor, options, status area, and lifecycle callbacks. Add the document handlers, cell-editing method, and helpers from the following sections inside the same @code block, or use the complete page in the sample repository.
@page "/"
@inject HttpClient Http
@using TXTextControl.TXSheetControl.Blazor
@using TXTextControl.TXSheetControl.Server
<PageTitle>TX Sheet Control: Blazor WebAssembly</PageTitle>
<main>
<p class="eyebrow">Blazor WebAssembly · TX Sheet Control</p>
<h1>Getting Started with TX Sheet Control</h1>
<p class="subtitle">Configure the editor, load a workbook, and change cells with the typed C# API.</p>
<div class="actions">
<button id="load-template" class="primary" disabled="@IsDisabled" @onclick="LoadTemplateAsync">Load sample XLSX</button>
<label class="file-picker @(IsDisabled ? "disabled" : "")">
Open local XLSX
<InputFile id="open-workbook" OnChange="OpenFileAsync" accept=".xlsx" disabled="@IsDisabled" />
</label>
<button id="load-csv" disabled="@IsDisabled" @onclick="LoadCsvAsync">Load CSV</button>
<button id="update-cells" disabled="@IsDisabled" @onclick="UpdateCellsAsync">Update cells</button>
</div>
<p id="sheet-status" class="status" role="status" aria-live="polite">@status</p>
@if (warnings.Length > 0)
{
<ul class="warnings">
@foreach (var warning in warnings)
{
<li>@warning.Code: @warning.Message</li>
}
</ul>
}
@if (options is not null)
{
<div class="editor-frame">
<TXSheetControl Options="options" Height="600" Ready="OnReadyAsync" Error="OnError" Class="sheet-editor" />
</div>
}
</main>
@code {
private const long MaximumFileSize = 10 * 1024 * 1024;
private SheetControlOptions? options;
private BlazorSheetControl? control;
private string status = "Reading license...";
private XlsxWarning[] warnings = [];
private bool isBusy = true;
private bool IsDisabled => isBusy || control is null;
protected override async Task OnInitializedAsync()
{
try
{
var license = await Http.GetStringAsync("tx-sheet-control-license.txt");
options = CreateOptions(license);
status = "Starting spreadsheet...";
}
catch (Exception error)
{
status = $"Could not read the license: {error.Message}";
isBusy = false;
}
}
private static SheetControlOptions CreateOptions(string license) => new()
{
License = license,
Theme = "light",
Language = "en",
Locale = "en-US",
Rows = 100,
Columns = 20,
Areas = new ControlAreas
{
Ribbon = true,
FormulaBar = true,
SheetTabs = true,
StatusBar = true
},
Ribbon = new RibbonOptions
{
Layout = "compact",
DisplayMode = "expanded",
Tabs = new Dictionary<string, RibbonItemOptions>
{
["reporting"] = new() { Visible = false }
},
Groups = new Dictionary<string, RibbonItemOptions>
{
["home.clipboard"] = new() { Enabled = false }
},
Buttons = new Dictionary<string, RibbonItemOptions>
{
["home.font.italic"] = new() { Visible = false }
}
}
};
private async Task OnReadyAsync(BlazorSheetControl editor)
{
control = editor;
try
{
var sheet = await editor.Workbook.Sheets.AtAsync(0);
await sheet.Cell("A1").SetTextAsync("Hello from Blazor WebAssembly");
await editor.SelectRangeAsync(sheet, "A1");
status = "Ready. Load a document or update the cells.";
}
catch (Exception error)
{
status = $"Initialization failed: {error.Message}";
}
finally
{
isBusy = false;
}
}
private void OnError(SheetControlErrorEventArgs error)
{
status = $"{error.Code}: {error.Message}";
isBusy = false;
}
}
A standalone WebAssembly page needs no @rendermode directive. OnInitializedAsync can fetch the license, but the spreadsheet API becomes available only when the component invokes Ready.
License, Areas, and Ribbon Customization
SheetControlOptions.License receives the complete issued license text. The other options configure the initial editor:
- Appearance:
Themeselectslight,dark, orauto.Languagecontrols the UI language andLocalecontrols number and date formatting. - Worksheet capacity:
RowsandColumnsset the initial capacity. They do not describe the number of populated cells in a workbook. - Editor areas:
ControlAreasindependently shows or hides the ribbon, formula bar, sheet tabs, and status bar. The sample shows all four areas. - Ribbon: Typed
RibbonOptionschooses the compact layout. Dictionaries keyed by stable item IDs hide Reporting and Italic and disable the Clipboard group. - Host height: The component parameter
Height="600"sets the editor height in CSS pixels.
Use Layout = "classic" for the full ribbon or DisplayMode = "tabs-only" to show just the tabs until a tab is selected. Ribbon and area settings survive document loads. Hiding or disabling a command changes the UI; it does not restrict workbook API calls.
Access the Typed API After Ready
The Ready callback receives a BlazorSheetControl. Store it in a field, as OnReadyAsync does, and use its Workbook property in later button handlers. This is the Blazor equivalent of obtaining the JavaScript control instance; no JavaScript getControl call is necessary.
await editor.Workbook.Sheets.AtAsync(0) resolves the first worksheet. Its Cell, Range, and Columns members return typed handles with asynchronous operations. The shared document types are in TXTextControl.TXSheetControl.Server, even when the application references only the Blazor package. That namespace does not mean this browser editor runs a native backend engine.
Await each operation before using its result. The sample keeps its actions disabled until initialization completes. The Error callback reports component initialization and callback failures; awaited API methods also need normal exception handling.
Load XLSX Documents and CSV Data
Add these handlers inside the page's @code block. StreamType.SpreadsheetML selects XLSX input; the method consumes bytes or a stream, rather than choosing a format from a filename extension.
private Task LoadTemplateAsync() => RunActionAsync(async editor =>
{
var bytes = await Http.GetByteArrayAsync("documents/first-steps.xlsx");
var result = await editor.LoadAsync(bytes, StreamType.SpreadsheetML);
await FitColumnsAsync(editor);
ShowLoadResult(result, "Sample XLSX");
});
private Task OpenFileAsync(InputFileChangeEventArgs args) => RunActionAsync(async editor =>
{
await using var stream = args.File.OpenReadStream(MaximumFileSize);
var result = await editor.LoadAsync(stream, StreamType.SpreadsheetML);
await FitColumnsAsync(editor);
ShowLoadResult(result, "Local XLSX");
});
private Task LoadCsvAsync() => RunActionAsync(async editor =>
{
var csv = string.Join(Environment.NewLine,
"Item,Quantity,Unit price",
"Consulting,2,120",
"Training,3,80");
var result = await editor.LoadTextAsync(csv, StreamType.CSV, new CsvLoadOptions
{
SheetName = "Orders",
Delimiter = ",",
DecimalSeparator = "."
});
await FitColumnsAsync(editor);
ShowLoadResult(result, "CSV data");
});
Load sample XLSX fetches documents/first-steps.xlsx through HttpClient and passes the returned byte array to LoadAsync. A WebAssembly component cannot use a server filesystem path; it obtains document bytes from a URL, a selected file, or an application API.
Open local XLSX uses the Blazor InputFile component. Its change event supplies an IBrowserFile; OpenReadStream(MaximumFileSize) enforces this sample's 10 MiB limit. The C# handler reads the selected file in the browser. The caller owns the stream and disposes it with await using.
Load CSV passes text to LoadTextAsync with StreamType.CSV. CsvLoadOptions sets the worksheet name, delimiter, and decimal separator. The import replaces the workbook with a worksheet named Orders, containing the item, quantity, and unit price columns.
A successful load returns LoadResult.Warnings. The sample displays these nonfatal conversion notices in the page. A failed operation is handled separately by the action helper. After loading a replacement document, obtain fresh worksheet, cell, and range handles; handles from the previous document are no longer valid.
Change Cell Text, Values, and Formulas
The Update cells button resolves a worksheet from the current document and fills a small calculation. Add the following method and its column-width helper to the same @code block:
private Task UpdateCellsAsync() => RunActionAsync(async editor =>
{
// Loads replace the document. Resolve a fresh worksheet for this operation.
var sheet = await editor.Workbook.Sheets.AtAsync(0);
await sheet.Range("A1:D1").SetValuesAsync([["Service", "Quantity", "Unit price", "Total"]]);
await sheet.Cell("A2").SetTextAsync("Consulting");
await sheet.Cell("B2").SetValueAsync(2);
await sheet.Cell("C2").SetValueAsync(120);
await sheet.Cell("D2").SetFormulaAsync("=B2*C2");
await sheet.Range("A1:D1").FormatAsync(new { bold = true, fillColor = "#e5eef4" });
await sheet.Range("C2:D2").FormatAsync(new { numberFormatCode = "#,##0.00" });
await FitColumnsAsync(editor);
await editor.SelectRangeAsync(sheet, "D2");
var total = await sheet.Cell("D2").GetValueAsync();
status = $"Cells updated. D2 calculates 2 × 120 = {total.GetDecimal():0.00}.";
});
private static async Task FitColumnsAsync(BlazorSheetControl editor)
{
var sheet = await editor.Workbook.Sheets.AtAsync(0);
await sheet.Columns.At(0).SetWidthAsync(new { pixels = 160 });
await sheet.Columns.At(1).SetWidthAsync(new { pixels = 100 });
await sheet.Columns.At(2).SetWidthAsync(new { pixels = 120 });
await sheet.Columns.At(3).SetWidthAsync(new { pixels = 100 });
}
SetTextAsync writes literal text. SetValueAsync writes a typed scalar, such as a number, while SetFormulaAsync writes a formula with its leading equals sign. SetValuesAsync fills a whole range with a matching matrix, reducing the number of individual calls.
B2 contains 2 and C2 contains 120, so =B2*C2 in D2 evaluates to 240. GetValueAsync reads the calculated scalar as a JsonElement; this example uses GetDecimal(). To read formatted display text or the formula itself, use GetDisplayTextAsync or GetFormulaAsync.
FormatAsync styles the header and numeric cells, SetWidthAsync sets readable column widths, and SelectRangeAsync selects D2 so its formula appears in the formula bar.
Handle Actions and Conversion Notices
Complete the page with these helpers. RunActionAsync serializes the sample's button actions using its busy state and reports exceptions in the status area. ShowLoadResult displays successful import notices independently of failures.
private async Task RunActionAsync(Func<BlazorSheetControl, Task> action)
{
if (control is null || isBusy)
{
return;
}
isBusy = true;
try
{
await action(control);
}
catch (Exception error)
{
status = $"Operation failed: {error.Message}";
}
finally
{
isBusy = false;
}
}
private void ShowLoadResult(LoadResult result, string source)
{
warnings = result.Warnings;
status = warnings.Length == 0 ? $"{source} loaded." : $"{source} loaded with {warnings.Length} conversion notice(s).";
}
The component owns the browser control and disposes it when removed from the render tree. Keep document handles scoped to the current workbook. If you change mount settings such as the license or initial capacity, recreate the component deliberately with @key; supported UI options can be updated by assigning a new options record.
Run the Complete Sample
The complete Blazor WebAssembly sample is available in the GitHub repository. It includes a named solution and project, the complete Razor page, styles, and sample workbook. Configure your NuGet source and supply your own license at the location described above, then run:
dotnet run --project TXSheetControlBlazorWebAssemblyGettingStarted/TXSheetControlBlazorWebAssemblyGettingStarted.csproj --launch-profile http
Try the three loading options, then select Update cells. The page should report a total of 240.00. The two hosting samples use the same workbook operations; their startup, license loading, and application-file access reflect their hosting model.
Deploy the published wwwroot to a static host with the required JavaScript, WebAssembly, JSON, text, and font MIME types. Preserve the application base URI and configure fallback routing for client-side routes. This sample needs no native spreadsheet engine on the hosting server.
Read the Blazor integration guide, Blazor API reference, and loading and saving guide for further examples. For the other hosting model, see Getting Started with TX Sheet Control in Blazor Server.
Frequently Asked Questions
Use TXTextControl.TXSheetControl.Blazor 2.0.0 with .NET 10 or newer. It includes the editor, fonts, styles, and portable C# workbook API.
Both the WebAssembly component code and the spreadsheet editor run in the browser. The sample does not need a Blazor Server circuit or a native server processing engine.
Serve the issued license text as wwwroot/tx-sheet-control-license.txt, load it with HttpClient, and pass the complete text to SheetControlOptions.License. Browser configuration and signed browser licenses are public application content.
No. The Ready callback supplies a BlazorSheetControl. Store it and use its Workbook property and the typed asynchronous C# methods after initialization.
Use InputFile and pass the selected file stream to LoadAsync with StreamType.SpreadsheetML. The sample allows files up to 10 MiB and reports conversion notices separately from failures.
No. Loading replaces the workbook. Resolve fresh worksheet, range, and cell handles from the current document before editing it.
![]()
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- TX Sheet Control 2.0.0
- Visual Studio 2026
TX Sheet Control
Excel-compatible spreadsheet editing, a robust calculation engine, and interactive dashboards for business applications.
Related Posts
Getting Started with TX Sheet Control in Blazor Server
Build your first Blazor Server spreadsheet application with TX Sheet Control. Configure the license, editor areas, and ribbon, load workbooks and CSV data, and edit cell text, values, and formulas…
JavaScriptASP.NET CoreGetting Started
Getting Started with TX Sheet Control in ASP.NET Core
Build your first ASP.NET Core spreadsheet application with TX Sheet Control. Configure the license, editor areas, and ribbon, load XLSX files and CSV data, and use getControl to change cell text,…
TX Sheet Control 2.0 Is Now Available: Spreadsheets and Dashboards for Your…
Today, we are proud to officially release TX Sheet Control 2.0. The newest member of the Text Control product family brings Excel-compatible spreadsheet editing, a powerful calculation engine,…
