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, values, and formulas. Includes a complete sample application.

TX Sheet Control adds a spreadsheet editor to an ASP.NET Core web application with a single Razor Tag Helper. In this tutorial, we create an MVC application, configure the license and editor areas, customize the ribbon, load workbooks, and use the JavaScript API to write text, numbers, and formulas into cells.
The sample uses .NET 10 and TX Sheet Control 2.0.0. The ASP.NET Core package includes the browser editor and its fonts. This application does not require the separate server processing package.
Create the ASP.NET Core Application
Create an ASP.NET Core Web App (Model-View-Controller) targeting .NET 10. From the command line, run:
First configure the Text Control private NuGet feed with the nuget.config supplied with your download, or use the supplied local NuGet folder. See Download TX Sheet Control for the package and license download steps.
dotnet new mvc -n TXSheetControlGettingStarted -f net10.0
cd TXSheetControlGettingStarted
dotnet add package TXTextControl.TXSheetControl.AspNetCore --version 2.0.0
Configure the Application and Register the Tag Helper
Replace Program.cs with the following code. The MVC services and route serve the view. UseStaticWebAssets enables the package assets, and UseTXSheetControlAssets adds the editor asset middleware before static assets are served.
using TXTextControl.TXSheetControl.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
builder.Services.AddControllersWithViews();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseTXSheetControlAssets();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.Run();
Keep the standard MVC imports in Views/_ViewImports.cshtml and add this registration:
@addTagHelper *, TXTextControl.TXSheetControl.AspNetCore
The Tag Helper includes its browser script and initializer automatically, once per page. The editor installs its bundled styles inside its Shadow DOM. No manual references to the package scripts or stylesheet are required.
Create an Instance with Options
Copy your tx-sheet-control.license file into the application root, beside Program.cs. Then replace Views/Home/Index.cshtml with this view:
@using TXTextControl.TXSheetControl.AspNetCore
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostEnvironment
@{
ViewData["Title"] = "TX Sheet Control: First Steps";
var options = new TXSheetControlOptions
{
License = System.IO.File.ReadAllText(System.IO.Path.Combine(
HostEnvironment.ContentRootPath, "tx-sheet-control.license")),
Theme = "light",
Language = "en",
Locale = "en-US",
Rows = 100,
Columns = 20,
Areas = new TXSheetControlAreas
{
Ribbon = true,
FormulaBar = true,
SheetTabs = true,
StatusBar = true
},
Ribbon = new
{
layout = "compact",
displayMode = "expanded",
tabs = new Dictionary<string, object>
{
["reporting"] = new { visible = false }
},
groups = new Dictionary<string, object>
{
["home.clipboard"] = new { enabled = false }
},
buttons = new Dictionary<string, object>
{
["home.font.italic"] = new { visible = false }
}
}
};
}
<script src="~/js/first-steps.js" asp-append-version="true"></script>
<tx-sheet-control id="spread" height="600" options="options" />
The License option receives the complete contents of the license file. The sample resolves the path from the application content root. Include the file at that location when deploying, or supply the same text through your application configuration. The browser editor receives the license through its options; never include your actual license in a shared sample.
The other options configure the initial editor:
- Appearance and locale:
Themeselectslight,dark, orauto.Languageselects the UI language, whileLocalecontrols number and date formatting. - Worksheet capacity:
RowsandColumnsset the initial capacity. They do not limit how many populated rows a loaded workbook contains. - Editor areas:
Areasshows or hides the ribbon, formula bar, sheet tabs, and status bar independently. Set a property tofalseto hide that area. - Host size: The Tag Helper's
height="600"sets the editor host height in CSS pixels. The IDspreadidentifies this instance in JavaScript.
Customize the Ribbon
Ribbon accepts a JavaScript-style configuration object. Use camelCase names inside this object, as shown above. The example chooses the compact layout, hides the Reporting tab, disables the Clipboard group, and hides the Italic button.
Ribbon item IDs are independent of the UI language. After initialization, inspect control.ui.ribbon.items for the catalog. For the full group layout, use layout = "classic"; for a collapsed command area, use displayMode = "tabs-only". Ribbon settings survive document loads. Hiding or disabling a ribbon command controls the UI; it does not restrict workbook API calls.
Wait for the Editor and Access the API
The Tag Helper initializes the editor asynchronously. Register a txsheetcontrolready listener during page loading. Its event.detail contains the initialized spreadsheet instance. The ID check keeps the handler specific to this editor when a page contains several controls.
Create wwwroot/js/first-steps.js with the following code. It writes the first text into A1 and handles initialization failures:
document.addEventListener('txsheetcontrolready', event => {
if (event.target.id !== 'spread') {
return;
}
const control = event.detail;
control.workbook.sheets.at(0).cell('A1').setText('Hello from TX Sheet Control');
});
document.addEventListener('txsheetcontrolerror', event => {
if (event.target.id === 'spread') {
console.error('The editor could not start.', event.detail);
}
});
Load this application script before the Tag Helper, as the view does, so its listeners are in place before initialization finishes. Later, for example in a button handler, obtain the same instance with getControl. It accepts either the host ID or the host element and returns undefined if no instance is registered. Add this helper to the same JavaScript file:
async function getSpreadsheet() {
const control = TXTextControl.TXSheetControl.getControl('spread');
if (!control) {
throw new Error('The spreadsheet has not been created yet.');
}
await control.ready;
return control;
}
getControl locates the instance; it does not wait for initialization. Await control.ready before accessing the workbook. The complete sample also keeps its action buttons disabled until the ready event.
Load Documents
Call the editor's asynchronous load method with the document data and a StreamType. The format selector tells the API how to interpret the input. In the Tag Helper integration, these types are available through TXTextControl.TXSheetControl.StreamType.
Load an XLSX from the Application
Place an XLSX file at wwwroot/documents/first-steps.xlsx. Add a button to the view above the script and editor:
<button id="load-template" type="button"
data-url="@Url.Content("~/documents/first-steps.xlsx")">Load sample XLSX</button>
Url.Content resolves the URL relative to the application, including when it is hosted under a virtual path. Fetch the bytes, check the HTTP response, and load them as SpreadsheetML, the stream type for XLSX:
document.getElementById('load-template').addEventListener('click', async event => {
const url = event.currentTarget.dataset.url;
try {
const control = await getSpreadsheet();
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Could not load the sample workbook (HTTP ${response.status}).`);
}
const bytes = new Uint8Array(await response.arrayBuffer());
const result = await control.load(bytes, TXTextControl.TXSheetControl.StreamType.SpreadsheetML);
result.warnings.forEach(warning => console.warn(warning));
} catch (error) {
console.error('Loading the workbook failed.', error);
}
});
Open a Local XLSX File
A file selected by the user supplies the same bytes through File.arrayBuffer(). Add this input above the application script:
<input id="open-workbook" type="file" accept=".xlsx" />
Then add its change handler to first-steps.js. This reads the selected file in the browser:
document.getElementById('open-workbook').addEventListener('change', async event => {
const input = event.target;
const file = input.files[0];
if (!file) {
return;
}
try {
const control = await getSpreadsheet();
const bytes = new Uint8Array(await file.arrayBuffer());
const result = await control.load(bytes, TXTextControl.TXSheetControl.StreamType.SpreadsheetML);
result.warnings.forEach(warning => console.warn(warning));
} catch (error) {
console.error('Opening the workbook failed.', error);
} finally {
input.value = '';
}
});
Load CSV Text
CSV can be loaded directly from a string. Add a <button id="load-csv" type="button">Load CSV</button> above the script, then register this handler:
document.getElementById('load-csv').addEventListener('click', async () => {
try {
const control = await getSpreadsheet();
const csv = 'Item,Quantity,Unit price\nConsulting,2,120\nTraining,3,80';
const result = await control.load(csv, TXTextControl.TXSheetControl.StreamType.CSV, {
sheetName: 'Orders',
delimiter: ',',
decimalSeparator: '.'
});
result.warnings.forEach(warning => console.warn(warning));
} catch (error) {
console.error('Loading CSV failed.', error);
}
});
CSV imports replace the workbook with one worksheet containing the tabular values. For complete workbook files, use XLSX, StreamType.OpenDocumentSpreadsheet for ODS, or StreamType.InternalWorkbookFormat for TXWB. PDF is an export format.
Always await a load before editing the new document, inspect result.warnings, and handle rejected promises. Loading replaces the document, so reacquire worksheet, range, and cell handles afterward. A conversion warning can accompany a successful load; the sample workbook, for example, reports that custom document properties are retained in the original package but are not projected into the native model.
Change Cell Text, Values, and Formulas
Add a <button id="update-cells" type="button">Update cells</button> above the script. Its handler retrieves the current editor, acquires the first worksheet, and writes a small calculation:
document.getElementById('update-cells').addEventListener('click', async () => {
try {
const control = await getSpreadsheet();
const sheet = control.workbook.sheets.at(0);
sheet.cell('A1').setText('Service');
sheet.cell('B1').setText('Quantity');
sheet.cell('C1').setText('Unit price');
sheet.cell('D1').setText('Total');
sheet.cell('A2').setText('Consulting');
sheet.cell('B2').setValue(2);
sheet.cell('C2').setValue(120);
sheet.cell('D2').setFormula('=B2*C2');
sheet.range('A1:D1').format({ bold: true, fillColor: '#e5eef4' });
sheet.range('C2:D2').format({ numberFormatCode: '#,##0.00' });
sheet.columns.at(0).setWidth({ pixels: 160 });
sheet.columns.at(1).setWidth({ pixels: 100 });
sheet.columns.at(2).setWidth({ pixels: 120 });
sheet.columns.at(3).setWidth({ pixels: 100 });
console.log(sheet.cell('D2').value); // 240
} catch (error) {
console.error('Updating cells failed.', error);
}
});
setText writes literal text, including leading zeros or a leading equals sign. setValue writes a typed scalar such as a number. setFormula writes a formula with its leading equals sign. Read a cell's calculated result through value, its formatted display through displayText, and its formula through formula.
Here, B2 contains 2 and C2 contains 120, so D2 calculates 240 and displays 240.00. The range API formats the header and numeric cells, while the column API sets readable widths.
Run the Complete Sample
Download the complete ASP.NET Core sample. It includes the view, JavaScript, and sample XLSX. Add your own tx-sheet-control.license beside Program.cs and configure your NuGet source before running dotnet run.
Try Load CSV, Open local XLSX, or Load sample XLSX, then select Update cells. The complete sample disables its actions during initialization and loading, displays errors in a status area, and reports conversion warnings. The code above shows each operation individually.
Continue with the ASP.NET Core integration guide, the loading and saving guide, and the JavaScript API reference.
Frequently Asked Questions
TXTextControl.TXSheetControl.AspNetCore 2.0.0 requires .NET 10 or newer. It includes the browser editor and its static fonts and works independently of the server processing package.
Pass the complete contents of tx-sheet-control.license through TXSheetControlOptions.License. Use Areas.Ribbon, Areas.FormulaBar, Areas.SheetTabs, and Areas.StatusBar to show or hide the editor areas.
Yes. TXSheetControlOptions.Ribbon accepts a camelCase configuration object for the layout, displayMode, tabs, groups, and buttons. Item IDs are language-independent, and settings survive document loads.
Use the instance in the txsheetcontrolready event or retrieve it with TXTextControl.TXSheetControl.getControl using the host ID or element. Check that the instance exists and await control.ready before accessing its workbook.
Read the file into a Uint8Array or ArrayBuffer and await control.load with StreamType.SpreadsheetML. Inspect the returned conversion warnings and reacquire worksheet, range, and cell handles after loading the new document.
![]()
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
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,…
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…
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…
Inside the TX Sheet Control Spreadsheet Editor: A Complete Spreadsheet for…
Learn how the TX Sheet Control spreadsheet editor brings a complete spreadsheet into JavaScript, Angular, ASP.NET Core, and Blazor applications. This article covers the ribbon, 522 formula…
JavaScriptASP.NET CoreDOCX Editor
How to Embed a DOCX Editor in a Web Application (ASP.NET Core)
This tutorial shows how to embed a DOCX editor in an ASP.NET Core web application with TX Text Control. It covers setting up the editor, loading a DOCX document, and editing it with true WYSIWYG…
