Generating and editing spreadsheets from server-side .NET code has always been a source of friction. The built-in .NET base class library has no native support for the XLSX format, so developers often reach for Office Interop, which requires Excel installed on the host, or they wrestle with raw OpenXML and end up writing hundreds of lines to produce a basic report.
For teams that need to c# open xlsx file workflows at scale, a dedicated spreadsheet library removes the ceremony. Xceed Workbooks pour .NET provides a managed API that creates, reads, and modifies XLSX files without Excel, without COM, and without pages of boilerplate.
This tutorial walks through the core patterns: creating a new workbook, opening an existing one, modifying cells and styles, and saving changes. Every example uses the real Xceed.Workbooks.NET namespace and compiles against the current v3.0 package.
Why a dedicated library beats Interop for xlsx c# work
Office Interop has two deal-breaking limitations for backend scenarios. First, it demands a full Excel installation on the server, which Microsoft explicitly recommends against for unattended execution. Second, it leaks COM handles, and threading models clash with ASP.NET and worker services. As a result, any Excel automation that runs inside IIS, a Windows service, or a container tends to fail unpredictably.
Raw OpenXML, meanwhile, is accurate but verbose. A single cell write requires locating the sheet part, finding the correct row, creating an inline string or shared string reference, and computing the A1 reference manually. For anything beyond trivial output, the code becomes unmaintainable.
Xceed Workbooks for .NET is a fully managed library that reads and writes XLSX directly. It runs on .NET Framework 4.0 and later, .NET Core 3.0, and .NET 5 through 10, so the same code works on Windows, Linux, and containers. Since the library depends on nothing outside the managed runtime, deployment is a single NuGet reference.
Installing the package
Add the package from NuGet:
Install-Package Xceed.Workbooks.NET
dotnet add package Xceed.Workbooks.NET
The 45-day trial runs without a license key, so you can evaluate the full feature set before purchasing. Once installed, bring in the namespace:
using Xceed.Workbooks.NET;
Creating a new XLSX file in C#
The entry point is the static Workbook.Create() method. It returns an IDisposable workbook, so wrap it in a using block to guarantee the file handle closes. A new workbook comes with one default worksheet at index zero.
using Xceed.Workbooks.NET;
using (var workbook = Workbook.Create("SalesReport.xlsx"))
{
var sheet = workbook.Worksheets[0];
sheet.Cells["A1"].Value = "Product";
sheet.Cells["B1"].Value = "Units Sold";
sheet.Cells["C1"].Value = "Revenue";
sheet.Cells["A2"].Value = "Widget";
sheet.Cells["B2"].Value = 120;
sheet.Cells["C2"].Value = 4799.40;
sheet.Cells["A1"].Style.Font.Bold = true;
sheet.Cells["B1"].Style.Font.Bold = true;
sheet.Cells["C1"].Style.Font.Bold = true;
workbook.Save();
}
Notice how cell addressing uses the familiar A1 notation. Internally, the library also exposes row and column indexers, so you can build addresses dynamically when generating rows in a loop. As a result, migrating existing Interop code becomes straightforward.
Using R1C1 style indexing
For programmatic generation, numeric indexing is often cleaner than string concatenation. Both styles reference the same underlying cell grid.
using (var workbook = Workbook.Create("Grid.xlsx"))
{
var sheet = workbook.Worksheets[0];
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 5; col++)
{
sheet.Cells[row, col].Value = (row + 1) * (col + 1);
}
}
workbook.Save();
}
How to open an XLSX file in C#
Opening an existing workbook uses Workbook.Load(). The library parses the XLSX package, resolves shared strings, and exposes every worksheet through the Worksheets collection. Since the load operation is lazy where possible, large files do not need to fully materialize before you read the first cell.
using Xceed.Workbooks.NET;
using (var workbook = Workbook.Load("SalesReport.xlsx"))
{
var sheet = workbook.Worksheets[0];
var productName = sheet.Cells["A2"].Value;
var unitsSold = sheet.Cells["B2"].Value;
var revenue = sheet.Cells["C2"].Value;
Console.WriteLine($"{productName}: {unitsSold} units, ${revenue}");
}
The Value property returns object because a cell can hold strings, numbers, booleans, dates, or formulas. Therefore, cast appropriately when you need a specific type. For numeric cells, the underlying storage is double, matching the OOXML specification.
Modifying an existing excel c# workbook
Modification follows the same pattern as creation, but you load the file first. After making changes, call Save() to overwrite, or SaveAs()to write to a new path. The following example loads a report, appends a new data row, updates a totals cell, and saves.
using (var workbook = Workbook.Load("SalesReport.xlsx"))
{
var sheet = workbook.Worksheets[0];
sheet.Cells["A3"].Value = "Gadget";
sheet.Cells["B3"].Value = 85;
sheet.Cells["C3"].Value = 3399.15;
sheet.Cells["A5"].Value = "TOTAL";
sheet.Cells["B5"].Value = 205;
sheet.Cells["C5"].Value = 8198.55;
sheet.Cells["A5"].Style.Font.Bold = true;
workbook.Save();
}
Working with multiple worksheets
Most real reports span several sheets: a summary tab, raw data, and reference lookups. The Worksheets collection supports iteration and index-based access, so you can loop through every tab or target one by name.
using (var workbook = Workbook.Load("QuarterlyReport.xlsx"))
{
foreach (var sheet in workbook.Worksheets)
{
Console.WriteLine($"Processing sheet: {sheet.Name}");
sheet.Cells["A1"].Style.Font.Bold = true;
}
workbook.Save();
}
Key features of Xceed Workbooks for .NET
Beyond the basic read/write cycle, the library covers the features that production reports typically need.
| Fonctionnalité |
Description |
| Cell styling |
Fonts, colors, borders, fills, alignment, and number formats |
| Formulas |
Write Excel formulas that recalculate when opened in Excel |
| Multiple sheets |
Add, remove, rename, and reorder worksheets |
| No Excel dependency |
Runs on servers, containers, and Linux under .NET Core/5+ |
| Streaming save |
Efficient handling of large workbooks |
| XLSX format |
Full OOXML support, compatible with Excel 2007 through 365 |
Best practices and performance tips
A few patterns will keep your spreadsheet code fast and reliable in production.
Always wrap workbooks in using blocks. The Workbook type implements IDisposable, and disposal releases the underlying file stream. If you skip disposal, the output file may remain locked until the process exits.
Minimize per-cell style assignments when generating large datasets. Instead, apply styling to a header row and leave data cells with default styles, or reuse style objects where the API permits. Since styles are stored once in the XLSX package and referenced by index, consolidated styles also produce smaller files.
When you need to c# open xlsx file contents for read-only analysis, load, read, and dispose without calling Save(). The library will not modify the source file unless you explicitly save.
Prefer numeric indexers inside tight loops. String-based A1 addresses require parsing on every call, so for workbooks with tens of thousands of rows, switching to Cells[row, col]noticeably reduces CPU time.
For cross-platform deployment, verify your target framework. .NET Framework 4.0+ and .NET Core 3.0+ through .NET 10 are all supported, so the same assembly typically works across Windows, Linux, and macOS hosts. Refer to the Microsoft .NET target framework documentation when choosing your TFM.
When built-in .NET controls are enough
If your application only needs to export a small CSV that Excel can open, you probably do not need a spreadsheet library at all. A simple StreamWriter with comma-separated values handles that case without any dependency. Similarly, if you are producing a one-off report in a desktop app where Excel is guaranteed to be installed, Office Interop may work for quick prototypes.
Where a managed library becomes necessary: server-side generation, cross-platform workloads, containerized services, styled multi-sheet reports, and any scenario where installing Excel on the host is not acceptable.
Build production-grade Excel reports in .NET
Try Xceed Workbooks for .NET free for 45 days. No Excel install, no COM, no license key required for the trial.
Download Free TrialView on NuGet
Questions fréquemment posées
Do I need Microsoft Excel installed to use Xceed Workbooks for .NET?
No. The library reads and writes XLSX files directly through managed code. It does not call Office Interop or depend on any Excel installation, so it runs safely on servers, Linux containers, and Azure App Service.
Which .NET versions does Xceed Workbooks for .NET support?
The package targets .NET Framework 4.0 and later, .NET Core 3.0, and .NET 5 through 10. As a result, the same code compiles across legacy desktop applications and modern cloud workloads.
Can I open password-protected XLSX files in C# with this library?</h3
Refer to the current product documentation for encryption support in your installed version. Security-related features evolve between major releases, so always check the v3.0 release notes for the exact capability set.
How do I edit multiple worksheets in a single workbook?
Access any sheet through workbook.Worksheets[index] or by iterating the Worksheets collection. Each worksheet exposes its own Cells indexer, so you can read and write across tabs before calling Save() once at the end.
Is there a free trial for Xceed Workbooks for .NET?
Yes. The 45-day evaluation runs with the full feature set and does not require a license key. After the trial, a commercial license unlocks production deployment. Visit the Xceed products page for licensing details.
Can I convert an XLSX file to other formats?
The core library focuses on XLSX read/write. For PDF output, many teams pair Workbooks with Xceed PDF or Xceed Words for .NET to generate final documents from spreadsheet data. Check the product documentation for the current conversion options in v3.0.