OpenStandardLibrary 1.2.0
dotnet add package OpenStandardLibrary --version 1.2.0
NuGet\Install-Package OpenStandardLibrary -Version 1.2.0
<PackageReference Include="OpenStandardLibrary" Version="1.2.0" />
<PackageVersion Include="OpenStandardLibrary" Version="1.2.0" />
<PackageReference Include="OpenStandardLibrary" />
paket add OpenStandardLibrary --version 1.2.0
#r "nuget: OpenStandardLibrary, 1.2.0"
#:package OpenStandardLibrary@1.2.0
#addin nuget:?package=OpenStandardLibrary&version=1.2.0
#tool nuget:?package=OpenStandardLibrary&version=1.2.0
Open Standard Library
A .NET library for reading and creating spreadsheet files in ODS, XLSX, and delimited formats (CSV, TSV, pipe-delimited). No external dependencies — just pure .NET.
Supported Formats
| Format | Generate | Import |
|---|---|---|
| ODS (OpenDocument Spreadsheet) | Yes | Yes |
| XLSX (Office Open XML) | Yes | Yes |
| Delimited (comma, tab, pipe, ASCII) | Yes | Yes |
Features
- Multi-sheet workbooks — create and import workbooks with multiple named sheets
- Cell value types — String, Float, Boolean, DateTime, and Int64
- Cell styling — bold, italic, underline, font color/name/size, background color, borders (thin/medium/thick with color per edge), and text wrapping. Written and read back for both XLSX and ODS
- Number formats —
CellStyle.NumberFormattakes an Excel format code (#,##0.00,0%,"$"#,##0.00,mmm d, yyyy,h:mm AM/PM, ...). Written to XLSX as-is and translated to ODS data styles; read back on import from both formats - Formatted values —
GetFormattedValue()returns a cell's value as a spreadsheet app displays it (1234.5with"$"#,##0.00becomes$1,234.50), using the invariant culture or one you pass - Column widths — manual
SetColumnWidth()or automaticAutoFitColumns()with min/max constraints. Written and read back for both XLSX and ODS - Freeze panes — freeze rows and/or columns with
FreezeRowsandFreezeColumns - Sheet visibility — hide sheets with
Visibility(Hidden, orVeryHiddenin XLSX); read and written in both XLSX and ODS - Auto-filters —
SetAutoFilter()for the full range or a custom range - Header row detection —
HasHeaderRow,HeaderNames, andGetColumn(string)for column-name-based access. Auto-detected on XLSX/ODS import when freeze panes or auto-filters are present - Streaming CSV reader —
ReadCsvRowsAsync()reads rows one at a time viaIAsyncEnumerablewith optional header detection and row limit - RFC 4180 quoting — delimited import handles quoted and unquoted values, including delimiters, doubled quotes, and line breaks inside quoted values
- File encoding options — UTF-8 (default), ASCII, Unicode (UTF-16), and UTF-32 for delimited files, on both export and import
- Date format for delimited export —
DelimitedDateFormat(e.g.yyyy-MM-dd) writes every DateTime cell in one format, independent of the machine's locale - Epoch conversion —
FromEpochSeconds(),FromEpochMilliseconds(),ToEpochSeconds(),ToEpochMilliseconds()extension methods on cells - Formulas — set
Formulaon a cell using Excel syntax (=SUM(A1:A10)); written to and read from XLSX and ODS, with automatic translation to ODS OpenFormula syntax. The library does not calculate results — see Formulas - File validation —
SpreadsheetValidatorchecks that XLSX, ODS, and delimited files are well-formed without importing them, returning structured errors and warnings (sheet, cell, row, rule code, message). Useful for vetting files produced by LLMs or other tools before they reach users - Formula safety checks — both validators flag formulas that reach outside the spreadsheet (
WEBSERVICE,HYPERLINK,RTD, DDE syntax,CALL, ...) and references to other workbooks, as warnings or, withTreatDangerousFormulasAsErrors, as errors - CSV injection protection —
EscapeFormulaLikeValuesprefixes formula-like text (=,+,-,@, tab, CR) with an apostrophe in delimited output, and both validators warn about such values - Import limits —
ImportOptionscaps the decompressed size and cell count of imported files, and XML document type declarations are rejected, so a small malicious file can't exhaust memory - Workbook validation —
Workbook.Validate()reports problems in the in-memory model (values that don't match their type, bad sheet names, formulas pointing at missing sheets, ...) and the Generate methods refuse to write an invalid file, throwingInvalidWorkbookExceptionwith the same structured issues - Dependency injection — implements
ISpreadsheetwithIDisposable/IAsyncDisposable
Installation
dotnet add package OpenStandardLibrary
Quick Start
Generate an XLSX file
using OoxSpreadsheet;
using OslSpreadsheet.Models;
using var spreadsheet = new Spreadsheet();
var sheet = spreadsheet.Workbook.AddSheet("Data");
sheet.AddCell(1, 1, "Name");
sheet.AddCell(1, 2, "Score");
sheet.AddCell(2, 1, "Alice");
sheet.AddCell(2, 2, "95.5", CellValueType.Float);
var bytes = await spreadsheet.GenerateXlsxFileAsync();
await File.WriteAllBytesAsync("output.xlsx", bytes);
Import and read by column name
using var spreadsheet = new Spreadsheet();
var workbook = await spreadsheet.ImportXlsxFileAsync(File.ReadAllBytes("input.xlsx"));
var sheet = workbook.Sheets[0];
// HasHeaderRow is auto-detected from freeze panes or auto-filters
if (sheet.HasHeaderRow)
{
var names = sheet.GetColumn("Name");
foreach (var cell in names)
Console.WriteLine(cell.Value);
}
Validate a file
using OslSpreadsheet.Validation;
var result = SpreadsheetValidator.Validate(File.ReadAllBytes("report.xlsx"), "report.xlsx");
if (!result.IsValid)
{
foreach (var issue in result.Errors)
Console.WriteLine($"{issue.Code} {issue.Sheet}!{issue.Cell}: {issue.Message}");
}
The Generate methods run the same kind of check on the workbook first, so a bad value never silently produces a broken file:
var cell = sheet.AddCell(2, 2, "n/a", CellValueType.Float);
var check = spreadsheet.Workbook.Validate(ValidationFileFormat.Xlsx);
// check.IsValid == false; check.Errors[0]: WB_CELL_NOT_NUMERIC at Data!B2
await spreadsheet.GenerateXlsxFileAsync(); // throws InvalidWorkbookException carrying the same result
See Validating Files for details.
Stream CSV rows
using var spreadsheet = new Spreadsheet();
using var stream = File.OpenRead("large-file.csv");
await foreach (var row in spreadsheet.ReadCsvRowsAsync(stream, hasHeaderRow: true, rowLimit: 100))
{
Console.WriteLine(string.Join(", ", row));
}
// Headers are available after iteration
Console.WriteLine($"Columns: {string.Join(", ", spreadsheet.CsvHeaders!)}");
Cell styling
var cell = sheet.AddCell(1, 1, "Header");
cell.Style = new CellStyle
{
Bold = true,
FontColor = "#FFFFFF",
BackgroundColor = "#2196F3",
BorderBottom = new CellBorder { Style = BorderStyle.Medium, Color = "#1565C0" },
WrapText = true
};
// Number formats use Excel format codes
sheet.AddCell(2, 1, "1234.5", CellValueType.Float).Style = new CellStyle { NumberFormat = "#,##0.00" };
sheet.AddCell(2, 2, "0.256", CellValueType.Float).Style = new CellStyle { NumberFormat = "0.0%" };
sheet.AddCell(2, 3, "9.99", CellValueType.Float).Style = new CellStyle { NumberFormat = "\"$\"#,##0.00" };
sheet.AddCell(2, 4, "2024-01-31", CellValueType.DateTime).Style = new CellStyle { NumberFormat = "mmmm d, yyyy" };
Formulas
sheet.AddCell(1, 1, "10", CellValueType.Float);
sheet.AddCell(2, 1, "20", CellValueType.Float);
var total = sheet.AddCell(3, 1);
total.Formula = "=SUM(A1:A2)"; // Excel A1 syntax; other sheets as 'Sheet Name'!A1
The library doesn't calculate formulas. Excel and LibreOffice compute them when the file is opened (generated XLSX files are flagged to recalculate on load), but tools that read stored values without calculating — such as pandas, file previewers, or this library's own import — see an empty result. If you already know the result, set it as the cell's Value and ValueType, and it will be stored as the cached result.
Epoch conversion
var cell = sheet.AddCell(1, 1, "1747650600");
cell.FromEpochSeconds(); // Value becomes "2025-05-19T10:30:00", ValueType becomes DateTime
// Or convert back
cell.ToEpochSeconds(); // Value becomes "1747650600", ValueType becomes Int64
Supported Frameworks
- .NET 8.0
- .NET 9.0
- .NET 10.0
Disclaimer
This software is provided "as is", without warranty of any kind. Use at your own risk. See the LICENSE file for full terms.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.