Introduction
Aspose.Cells FOSS for .NET is a free, MIT-licensed open-source library that enables .NET
developers to create, load, edit, and save Excel .xlsx workbooks without any Microsoft Office
installation or native COM dependency. It is distributed as the Aspose.Cells_FOSS NuGet
package and runs on Windows, macOS, Linux, Docker, and serverless environments.
The library covers the full workbook lifecycle: constructing Workbook objects from scratch or
from existing .xlsx files, navigating worksheets, reading and writing cell values of multiple
data types, evaluating formulas, applying Style objects, setting up conditional formatting
rules, adding data validations, managing hyperlinks and named ranges, and configuring page setup
for print. All operations work against .xlsx files with no runtime dependency beyond the NuGet
package itself.
Whether you are building a financial reporting API, a data export pipeline, or an automated test harness that validates spreadsheet output, Aspose.Cells FOSS for .NET provides a stable, audit-friendly foundation licensed for both open-source and commercial use.
Key Features
Workbook and Worksheet Management
Create workbooks from scratch or load existing .xlsx files using new Workbook() or
new Workbook(filePath). Access worksheets by index or name via WorksheetCollection, add and
rename sheets, set visibility, and save back to a file path or Stream with Workbook.Save().
Configure load-time repair with LoadOptions (TryRepairPackage, TryRepairXml) to handle
malformed files gracefully.
using Aspose.Cells_FOSS;
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue("Hello");
sheet.Cells["B1"].PutValue(123);
sheet.Cells["C1"].Formula = "=B1*2";
workbook.Save("hello.xlsx");
var loaded = new Workbook("hello.xlsx");
Console.WriteLine(loaded.Worksheets[0].Cells["C1"].Formula);
Console.WriteLine(loaded.Worksheets[0].Cells["C1"].StringValue);
Cell Styling and Formatting
Apply Style objects to cells for font properties, fill color, borders, number formats, and
alignment. Read the current style with Cell.GetStyle(), modify it, and commit with
Cell.SetStyle(). The styling API uses FillPattern.Solid with ForegroundColor for
background fills, and Style.Font.Bold for font weight control.
using Aspose.Cells_FOSS;
var workbook = new Workbook();
var cell = workbook.Worksheets[0].Cells["A1"];
cell.PutValue("Styled");
var style = cell.GetStyle();
style.Font.Bold = true;
style.Pattern = FillPattern.Solid;
style.ForegroundColor = Color.FromArgb(255, 241, 196, 15);
cell.SetStyle(style);
Console.WriteLine($"{cell.StringValue} / Bold={cell.GetStyle().Font.Bold}");
Conditional Formatting
Add conditional formatting rules to any cell range via ConditionalFormattingCollection.
Supported rule types include FormatConditionType.CellValue, Expression, ColorScale,
DataBar, and IconSet. Use OperatorType values such as Between, Equal, and
GreaterThan to define conditions, then assign a Style to matched cells for visual
highlighting.
using Aspose.Cells_FOSS;
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
var cfCollection = sheet.ConditionalFormattings[sheet.ConditionalFormattings.Add()];
cfCollection.AddArea(CellArea.CreateCellArea("A1", "A10"));
var rule = cfCollection[cfCollection.AddCondition(
FormatConditionType.CellValue, OperatorType.Between, "3", "7")];
var style = rule.Style;
style.Pattern = FillPattern.Solid;
style.ForegroundColor = Color.FromArgb(255, 255, 199, 206);
style.Font.Bold = true;
rule.Style = style;
workbook.Save("conditional-formatting.xlsx");
Data Validation
Define list, decimal, and custom validation rules on any cell range using
Worksheet.Validations. Each Validation instance supports ValidationType, OperatorType,
formula bounds, input prompts, error messages, and ValidationAlertType for warning versus
stop alerts. Validations survive a full save-load cycle.
using Aspose.Cells_FOSS;
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Name = "Validation Sheet";
var listIdx = sheet.Validations.Add(CellArea.CreateCellArea("A1", "A3"));
var listVal = sheet.Validations[listIdx];
listVal.Type = ValidationType.List;
listVal.Formula1 = "\"Open,Closed\"";
listVal.IgnoreBlank = true;
listVal.InCellDropDown = true;
listVal.ShowInput = true;
listVal.InputTitle = "Status";
listVal.InputMessage = "Pick a status";
workbook.Save("validations-sample.xlsx");
Hyperlinks and Named Ranges
Add external URLs, internal cell references, and mailto: links via
HyperlinkCollection.Add(). Set Hyperlink.TextToDisplay and Hyperlink.ScreenTip for
user-visible labels. Define workbook-scoped or sheet-scoped named ranges with
DefinedNameCollection.Add() to create stable anchors for formulas and chart data sources.
using Aspose.Cells_FOSS;
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue("Docs");
var link = sheet.Hyperlinks[sheet.Hyperlinks.Add("A1", 1, 1, "https://example.com/docs")];
link.TextToDisplay = "Docs";
link.ScreenTip = "External documentation";
var name = workbook.DefinedNames[workbook.DefinedNames.Add("PrimaryRange", "='Sheet1'!$A$1:$D$5")];
name.Comment = "Primary data range";
workbook.Save("hyperlinks-names.xlsx");
Console.WriteLine("Hyperlinks: " + sheet.Hyperlinks.Count);
Console.WriteLine("Defined names: " + workbook.DefinedNames.Count);
Quick Start
Install the package:
dotnet add package Aspose.Cells_FOSS
Create a workbook, write mixed-type values and a formula, save to .xlsx, then reload and verify:
using Aspose.Cells_FOSS;
var outputPath = Path.Combine(AppContext.BaseDirectory, "cell-data-roundtrip.xlsx");
var timestamp = new DateTime(2024, 5, 6, 7, 8, 9, DateTimeKind.Utc);
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue("Hello");
sheet.Cells["B1"].PutValue(123);
sheet.Cells["C1"].PutValue(true);
sheet.Cells["D1"].PutValue(12.5m);
sheet.Cells["E1"].PutValue(timestamp);
sheet.Cells["F1"].PutValue(10);
sheet.Cells["G1"].PutValue(20);
sheet.Cells["G1"].Formula = "=F1*2";
workbook.Save(outputPath);
var loaded = new Workbook(outputPath);
var loadedSheet = loaded.Worksheets[0];
Console.WriteLine(loadedSheet.Cells["A1"].StringValue);
Console.WriteLine(loadedSheet.Cells["G1"].Formula + " -> " + loadedSheet.Cells["G1"].StringValue);
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| Xlsx | .xlsx | ✓ | ✓ |
| Auto | (various) | ✓ | — |
Open Source & Licensing
Aspose.Cells FOSS for .NET is published under the MIT license. The package is distributed via
NuGet as Aspose.Cells_FOSS. MIT licensing permits use in both open-source and commercial
projects with no royalties or restrictions on redistribution.