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 using C#. Includes a complete sample.

TX Sheet Control brings a spreadsheet editor to Blazor Server 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 .NET 10 Blazor Web App with Interactive Server rendering. C# component code runs on the server and communicates with the browser through the Blazor circuit. The spreadsheet editor and its calculation engine run in the browser. The sample uses TX Sheet Control 2.0.0.
Create the Blazor Server 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 blazor -n TXSheetControlBlazorServerGettingStarted -f net10.0 --interactivity Server --empty
cd TXSheetControlBlazorServerGettingStarted
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
Keep the standard Blazor Web App host and routing components generated by the template. In Program.cs, register Interactive Server components and map their render mode. The sample also sets a 32 MiB circuit message limit for larger JSON payloads; choose a limit appropriate to your workload.
using TXSheetControlBlazorServerGettingStarted.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddHubOptions(options => options.MaximumReceiveMessageSize = 32 * 1024 * 1024);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
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 your tx-sheet-control.license file into the project folder, beside Program.cs. The page reads its complete contents with File.ReadAllTextAsync, resolving the path from HostEnvironment.ContentRootPath. Supply that file at the deployed content root as well, or read the same license text from your application configuration.
Open Components/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 "/"
@rendermode InteractiveServer
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostEnvironment
@using TXTextControl.TXSheetControl.Blazor
@using TXTextControl.TXSheetControl.Server
<PageTitle>TX Sheet Control: Blazor Server</PageTitle>
<main>
<p class="eyebrow">Blazor Server · 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 File.ReadAllTextAsync(Path.Combine(HostEnvironment.ContentRootPath, "tx-sheet-control.license"));
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 Server");
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;
}
}
The @rendermode InteractiveServer directive makes this page interactive. Prerendering can produce the initial host markup, while the spreadsheet initializes after interactive rendering and JavaScript interop are available. Calling the workbook API from OnInitializedAsync would be too early.
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 =>
{
await using var stream = File.OpenRead(Path.Combine(HostEnvironment.WebRootPath, "documents", "first-steps.xlsx"));
var result = await editor.LoadAsync(stream, 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 opens wwwroot/documents/first-steps.xlsx on the server using File.OpenRead, then passes the stream to BlazorSheetControl.LoadAsync. The browser control consumes the document bytes. Do not pass a filesystem name to the browser control itself: its filename overload is unsupported.
Open local XLSX uses the Blazor InputFile component. Its change event supplies an IBrowserFile; OpenReadStream(MaximumFileSize) enforces this sample's 10 MiB limit. The selected bytes pass through the Blazor Server circuit to the C# handler. 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 Server 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 TXSheetControlBlazorServerGettingStarted/TXSheetControlBlazorServerGettingStarted.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 complete ASP.NET Core publish output, including the component assets under _content/TXTextControl.TXSheetControl.Blazor/. Provide the license at the deployed content root and preserve normal Blazor circuit connectivity. Independent backend workbook jobs use the separate Server package and exchange document bytes explicitly.
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 WebAssembly.
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.
The spreadsheet engine runs in the browser. The Interactive Server component code runs on the server and reaches the browser control through Blazor interop.
Read the complete tx-sheet-control.license from the application content root and pass it to SheetControlOptions.License. Supply the file or equivalent configuration when deploying.
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 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…
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,…
