Toon.DotNet.Excel
1.7.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Toon.DotNet.Excel --version 1.7.1
NuGet\Install-Package Toon.DotNet.Excel -Version 1.7.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Toon.DotNet.Excel" Version="1.7.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toon.DotNet.Excel" Version="1.7.1" />
<PackageReference Include="Toon.DotNet.Excel" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Toon.DotNet.Excel --version 1.7.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toon.DotNet.Excel, 1.7.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Toon.DotNet.Excel@1.7.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Toon.DotNet.Excel&version=1.7.1
#tool nuget:?package=Toon.DotNet.Excel&version=1.7.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Toon.DotNet.Excel
Excel integration for ToonDotNet — convert Excel workbooks and worksheets to and from TOON format.
Features
Encoding — Excel → TOON
- Encode a single worksheet to a TOON root array, using the first row as column headers
- Encode a full workbook to a TOON root object, one key per sheet name
- Encode directly from a file path — open an
.xlsxand get back a TOON string in one call - Save as
.toon— read an Excel file and write the result straight to a.toonfile
Decoding — TOON → Excel
- Decode a TOON string into a new
XLWorkbook— root array becomesSheet1, root object becomes one sheet per key - Load a
.toonfile directly into a newXLWorkbook - Save as
.xlsx— decode a TOON string and write the result straight to an Excel file - Convert
.toonto.xlsx— file-to-file conversion in one call
Extension methods
IXLWorksheet.ToToon()— encode a worksheet inlineIXLWorkbook.ToToon()— encode all sheets inlinestring.ToExcelWorkbook()— decode a TOON string inline
Cell type handling
- Numbers, booleans, text and blank/null cells are round-tripped faithfully
DateTimevalues are encoded as ISO 8601 strings and parsed back on decodeTimeSpanvalues are preserved as formatted strings
Sheet management
- Multi-sheet workbooks are fully supported
- Sheet names are automatically sanitised (forbidden Excel characters removed, truncated to 31 characters)
- Duplicate sheet names after sanitisation receive a numeric suffix, e.g.
Sales (2)
Other
- All encode/decode calls accept the standard
EncodeOptionsandDecodeOptionsfromToon.DotNet - 56 unit tests, 100% passing, 78% code coverage
Installation
dotnet add package ToonDotNet.Excel
Compatibility
- .NET 10.0
- .NET 9.0
- .NET 8.0
How it works
Each worksheet is treated as tabular data: the first row provides column headers and every subsequent row becomes a TOON data row.
| Excel structure | TOON output |
|---|---|
| Single worksheet | Root array [N]{col1,col2,...}: |
| Full workbook | Root object — one key per sheet name |
Decoding reverses the mapping: a root TOON object creates one sheet per key; a root array creates a single sheet named Sheet1.
Quick start
Encode a worksheet to TOON
using ClosedXML.Excel;
using ToonDotNet.Excel;
using var workbook = new XLWorkbook("report.xlsx");
// Single sheet → root array
string toon = workbook.Worksheet("Sales").ToToon();
// [3]{id,product,amount}:
// 1,Widget,9.99
// 2,Gadget,19.99
// 3,Doohickey,4.99
Encode a full workbook to TOON
// All sheets → root object keyed by sheet name
string toon = workbook.ToToon();
// Sales[3]{id,product,amount}:
// 1,Widget,9.99
// ...
// Customers[2]{id,name}:
// 1,Alice
// 2,Bob
Decode TOON back to an Excel workbook
using var decoded = toon.ToExcelWorkbook();
decoded.SaveAs("output.xlsx");
Convert an Excel file directly to a TOON file
ToonExcel.SaveAsToon("report.xlsx", "report.toon");
Convert a TOON file directly to an Excel file
ToonExcel.ConvertToonToExcel("report.toon", "report.xlsx");
API overview
ToonExcel static class
Encoding (Excel → TOON)
| Method | Description |
|---|---|
ToonExcel.Encode(IXLWorksheet, EncodeOptions?) |
Encodes a single worksheet to a TOON string (root array) |
ToonExcel.Encode(IXLWorkbook, EncodeOptions?) |
Encodes all sheets to a TOON string (root object keyed by sheet name) |
ToonExcel.EncodeFile(string excelPath, EncodeOptions?) |
Opens an .xlsx file and returns its TOON representation |
ToonExcel.SaveAsToon(string excelPath, string toonPath, EncodeOptions?) |
Converts an .xlsx file and saves the result as a .toon file |
Decoding (TOON → Excel)
| Method | Description |
|---|---|
ToonExcel.Decode(string toon, DecodeOptions?) |
Decodes a TOON string into a new XLWorkbook |
ToonExcel.LoadToonFile(string toonPath, DecodeOptions?) |
Reads a .toon file and returns a new XLWorkbook |
ToonExcel.SaveAsExcel(string toon, string excelPath, DecodeOptions?) |
Decodes a TOON string and saves it as an .xlsx file |
ToonExcel.ConvertToonToExcel(string toonPath, string excelPath, DecodeOptions?) |
Converts a .toon file to an .xlsx file |
Note:
DecodeandLoadToonFilereturn a newXLWorkbookinstance. The caller is responsible for disposing it.
Extension methods
// IXLWorksheet
string toon = worksheet.ToToon(options);
// IXLWorkbook
string toon = workbook.ToToon(options);
// string
using XLWorkbook wb = toonString.ToExcelWorkbook(options);
Options
Options are passed directly from ToonDotNet and work identically here.
EncodeOptions
| Property | Default | Description |
|---|---|---|
Indent |
2 |
Spaces per indentation level |
Delimiter |
',' |
Column delimiter for tabular rows |
LengthMarker |
null |
Optional prefix for array lengths (e.g. '#' produces [#3]) |
DecodeOptions
| Property | Default | Description |
|---|---|---|
Indent |
2 |
Expected spaces per indentation level |
Strict |
true |
Validate array lengths and row counts |
var opts = new EncodeOptions { Delimiter = '|', Indent = 4 };
string toon = workbook.ToToon(opts);
Cell type handling
| Excel / TOON type | Encoding | Decoding |
|---|---|---|
| Number | double |
double written to cell |
| Boolean | true / false |
Boolean cell value |
| DateTime | ISO 8601 string | Parsed back to DateTime cell |
| TimeSpan | Formatted string | String cell value |
| Text | String literal | String cell value |
| Blank / null | null |
Empty cell |
Dependencies
- Toon.DotNet — core TOON encoding and decoding
- ClosedXML — Excel file reading and writing
License
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- ClosedXML (>= 0.105.0)
- Toon.DotNet (>= 1.7.1)
-
net8.0
- ClosedXML (>= 0.105.0)
- Toon.DotNet (>= 1.7.1)
-
net9.0
- ClosedXML (>= 0.105.0)
- Toon.DotNet (>= 1.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.