NanoXLSX is a library to generate and read Microsoft Excel files (XLSX) in an easy and native way. This package is the meta package of NanoXLSX and should be used in most cases as dependency in your project.
$ dotnet add package NanoXLSX![]()
NanoXLSX is a small .NET library written in C#, to create and read Microsoft Excel files in the XLSX format (Microsoft Excel 2007 or newer) in an easy and native way
:globe_with_meridians: Project website: https://picoxlsx.rabanti.ch
:page_facing_up: See the Change Log for recent updates.
NanoXLSX v3 is split into modular NuGet packages:
| Module | Status | Description |
|---|---|---|
| NanoXLSX.Core | :green_circle: Mandatory, Bundled | Core library with workbooks, worksheets, cells, styles. No external dependencies |
| NanoXLSX.Reader | :large_blue_circle: Optional, Bundled | Extension methods to read/load XLSX files. Depends on Core |
| NanoXLSX.Writer | :large_blue_circle: Optional, Bundled | Extension methods to write/save XLSX files. Depends on Core |
| :large_blue_circle: Optional, Bundled |
| In-line cell formatting (rich text). External repo. Depends on Core |
| NanoXLSX | :star: Meta-Package | Bundles all of the above. Recommended for most users |
Note: All bundled modules are included when you install the
NanoXLSXmeta-package. There are currently no non-bundled (standalone) modules.
For advanced scenarios, you can install only the specific packages you need (e.g. NanoXLSX.Core + NanoXLSX.Writer for write-only applications).
NanoXLSX v3 is a major release with significant architectural changes:
Color class supporting RGB, ARGB, indexed, theme and system colorsAddress and Range structs are now immutableUtils class split into DataUtils, ParserUtils, Validators:warning: Breaking changes from v2.x - There are breaking changes between NanoXLSX v2.6.7 and v3.0.0, mostly related to namespace changes and renamed enum values. See the Migration Guide for detailed upgrade instructions.
NanoXLSX v3.x is planned as the long-term supported version. Possible future enhancements include:
The reader of NanoXLSX follows the principle of "What You Can Write Is What You Can Read". Therefore, all information about workbooks, worksheets, cells and styles that can be written into an XLSX file by NanoXLSX, can also be read by it. There are some limitations:
NanoXLSX is originally based on PicoXLSX. However, NanoXLSX is now in the development lead, whereas PicoXLSX is a subset of it. The library is currently on compatibility level with .NET version 4.5 and .NET Standard 2.0. Newer versions should of course work as well. Older versions, like .NET 3.5 have only limited support, since newer language features were used.
*)The only requirement to compile the library besides .NET (v4.5 or newer) is the assembly WindowsBase, as well as System.IO.Compression. These assemblies are standard components in all Microsoft Windows systems (except Windows RT systems). If your IDE of choice supports referencing assemblies from the Global Assembly Cache (GAC) of Windows, select WindowsBase and Compression from there. If you want so select the DLLs manually and Microsoft Visual Studio is installed on your system, the DLL of WindowsBase can be found most likely under "c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll", as well as System.IO.Compression under "c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.IO.Compression.dll". Otherwise you find them in the GAC, under "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsBase" and "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression"
The NuGet package does not require dependencies
.NET Standard v2.0 resolves the dependency System.IO.Compression automatically, using NuGet and does not rely anymore on WindowsBase in the development environment. In contrast to the .NET >=4.5 version, no manually added dependencies necessary (as assembly references) to compile the library.
The Test project and GitHub Actions may also require dependencies like unit testing frameworks or workflow steps. However, none of these dependencies are essential to build the library. They are just utilities. The test dependencies ensure efficient unit testing and code coverage. The GitHub Actions dependencies are used for the automatization of releases and API documentation
By package Manager (PM):
Install-Package NanoXLSX
By .NET CLI:
dotnet add package NanoXLSX
:information_source: Note: Other methods like adding DLLs or source files directly into your project are technically still possible, but not recommended anymore. Use dependency management, whenever possible
Workbook workbook = new Workbook("myWorkbook.xlsx", "Sheet1"); // Create new workbook with a worksheet called Sheet1
workbook.WS.Value("Some Data"); // Add cell A1
workbook.WS.Formula("=A1"); // Add formula to cell B1
workbook.WS.Down(); // Go to row 2
workbook.WS.Value(DateTime.Now, Style.BasicStyles.Bold); // Add formatted value to cell A2
workbook.Save(); // Save the workbook as myWorkbook.xlsx
Workbook workbook = new Workbook("myWorkbook.xlsx", "Sheet1"); // Create new workbook with a worksheet called Sheet1
workbook.CurrentWorksheet.AddNextCell("Some Data"); // Add cell A1
workbook.CurrentWorksheet.AddNextCell(42); // Add cell B1
workbook.CurrentWorksheet.GoToNextRow(); // Go to row 2
workbook.CurrentWorksheet.AddNextCell(DateTime.Now); // Add cell A2
workbook.Save(); // Save the workbook as myWorkbook.xlsx
using NanoXLSX.Extensions;
Workbook wb = WorkbookReader.Load("basic.xlsx"); // Read the workbook
System.Console.WriteLine("contains worksheet name: " + wb.CurrentWorksheet.SheetName);
foreach (KeyValuePair<string, Cell> cell in wb.CurrentWorksheet.Cells)
{
System.Console.WriteLine("Cell address: " + cell.Key + ": content:'" + cell.Value.Value + "'");
}
See the full API-Documentation at: https://rabanti-github.github.io/NanoXLSX/.
The Demo Project contains 27 examples covering various use cases. The demo project is maintained in a separate repository. See the section NanoXLSX for the specific examples related to NanoXLSX.
See also: Getting started in the Wiki
Hint: You will find most certainly any function, and the way how to use it, in the Unit Test Project
NanoXLSX is licensed under the MIT License. See the LICENSE file for more details.