Use Cases for Aspose.Cells FOSS for .NET
Aspose.Cells FOSS for .NET is a pure managed .NET library that reads and writes XLSX files without requiring Microsoft Office or any external dependencies. The following use cases illustrate where the library fits into real-world .NET applications.
Report Generation
Generate XLSX reports programmatically in server-side or batch applications. Use Workbook, Worksheet, and Cell.PutValue() to write structured data, then call Workbook.Save() to produce the file.
using Aspose.Cells_FOSS;
var wb = new Workbook();
var ws = wb.Worksheets[0];
ws.Name = "Monthly Report";
ws.Cells["A1"].PutValue("Product");
ws.Cells["B1"].PutValue("Revenue");
ws.Cells["A2"].PutValue("Widget A");
ws.Cells["B2"].PutValue(12500.00m);
ws.Cells["A3"].PutValue("Widget B");
ws.Cells["B3"].PutValue(8750.00m);
ws.Cells["B4"].Formula = "=SUM(B2:B3)";
wb.Save("monthly-report.xlsx");This pattern scales to any number of rows and can be driven by data from a database or API response.
Processing Uploaded Spreadsheets
Read and validate XLSX files submitted by users through a web form or API endpoint. The Workbook constructor accepts a Stream, so no temporary file needs to be written to disk.
using Aspose.Cells_FOSS;
// IFormFile from ASP.NET Core controller
public async Task<IActionResult> Upload(IFormFile file)
{
using var stream = file.OpenReadStream();
var opts = new LoadOptions { TryRepairPackage = true };
var wb = new Workbook(stream, opts);
var ws = wb.Worksheets[0];
var firstRow = ws.Cells["A1"].StringValue;
// ... validate and process rows
return Ok(new { sheets = wb.Worksheets.Count, firstCell = firstRow });
}Use LoadDiagnostics.HasRepairs to detect files that required structural repair and surface that information to users.
Data Pipeline Extraction
Extract cell data from XLSX exports produced by third-party systems and feed values into a database or downstream service. Read cell values via Cell.StringValue and Cell.Value using row and column coordinates.
using Aspose.Cells_FOSS;
var wb = new Workbook("export.xlsx");
var ws = wb.Worksheets[0];
var records = new List<(string sku, double qty)>();
for (int row = 1; row <= 100; row++) // iterate known data range
{
var sku = ws.Cells[row, 0].StringValue;
if (string.IsNullOrEmpty(sku)) break;
var qty = (double)ws.Cells[row, 1].Value;
records.Add((sku, qty));
}
Console.WriteLine($"Extracted {records.Count} records");Applying Data Validation Before Save
Add dropdown or range validation rules before delivering an XLSX template to end users, ensuring they fill in only acceptable values.
using Aspose.Cells_FOSS;
var wb = new Workbook();
var ws = wb.Worksheets[0];
// Status column: dropdown
var statusVal = ws.Validations[ws.Validations.Add(CellArea.CreateCellArea("A2", "A100"))];
statusVal.Type = ValidationType.List;
statusVal.Formula1 = "\"Open,In Progress,Closed\"";
statusVal.InCellDropDown = true;
// Score column: 0–10 decimal range
var scoreVal = ws.Validations[ws.Validations.Add(CellArea.CreateCellArea("B2", "B100"))];
scoreVal.Type = ValidationType.Decimal;
scoreVal.Operator = OperatorType.Between;
scoreVal.Formula1 = "0";
scoreVal.Formula2 = "10";
scoreVal.ShowError = true;
wb.Save("template-with-validation.xlsx");Styling Output for Readability
Apply cell styles — fonts, fill colours, number formats, borders — to produce polished output. Create a Style instance directly, configure its properties, and apply it with Cell.SetStyle().
using Aspose.Cells_FOSS;
var wb = new Workbook();
var ws = wb.Worksheets[0];
// Header style
var headerStyle = new Style();
headerStyle.Font.IsBold = true;
headerStyle.Font.Size = 12;
headerStyle.ForegroundColor = System.Drawing.Color.FromArgb(0x4F, 0x81, 0xBD);
headerStyle.Pattern = FillPattern.Solid;
ws.Cells["A1"].PutValue("Name");
ws.Cells["B1"].PutValue("Score");
ws.Cells["A1"].SetStyle(headerStyle);
ws.Cells["B1"].SetStyle(headerStyle);
// Number format for score column
var numStyle = new Style();
numStyle.Custom = "0.00";
ws.Cells["B2"].SetStyle(numStyle);
ws.Cells["B2"].PutValue(98.5m);
wb.Save("styled-report.xlsx");