NanoXLSX
repository·master·Indexed 41 days ago
https://github.com/rabanti-github/nanoxlsxA lightweight, dependency-free .NET library for creating and reading Microsoft Excel (.xlsx) files. It features a modular architecture consisting of NanoXLSX.Core for base logic, NanoXLSX.Reader for parsing workbooks, NanoXLSX.Writer for creating files, and optional modules for formatting and compatibility. Compatible with .NET Standard 2.0 and .NET 4.5 or newer.
What's inside NanoXLSX
- NanoXLSX.Reader is a component of the NanoXLSX library designed to read Microsoft Excel workbooks in the XLSX format (Excel 2007 or newer). It provides the necessary logic to parse workbooks and access their constituent parts, such as worksheets and cells.
Overview of NanoXLSX.Writer
masterNanoXLSX.Writer is a component of the NanoXLSX library designed specifically for creating Microsoft Excel files in the XLSX format (Excel 2007 or newer). It provides the necessary tools to write workbooks and their constituent parts (such as worksheets and cells) directly to files or into memory streams.Understand NanoXLSX modules
masterNanoXLSX v3 uses a modular architecture. While the
NanoXLSXmeta-package is recommended for most users as it includes everything, you can pick specific modules:- NanoXLSX.Core: Mandatory. Contains workbooks, worksheets, cells, and styles. Has no external dependencies.
- NanoXLSX.Reader: Optional. Provides extension methods to read/load XLSX files.
- NanoXLSX.Writer: Optional. Provides extension methods to write/save XLSX files.
- NanoXLSX.Formatting: Optional. Provides in-line cell formatting (rich text).
- NanoXLSX.Compatibility: Optional. Handles compatibility features like external links.
Understand NanoXLSX package dependencies and scopes
masterNanoXLSX is modular. While the meta package installs everything, you can choose specific modules based on your needs:
- NanoXLSX.Core (Mandatory): Provides base functionalities including workbooks, worksheets, cells, and standard operations.
- NanoXLSX.Reader (Optional): Adds functions to read workbooks, worksheets, styles, and shared strings.
- NanoXLSX.Writer (Optional): Adds functions to write workbooks, worksheets, styles, and shared strings.
- NanoXLSX.Formatting (Optional): Enables in-line cell formatting (rich text).
Understand the purpose of NanoXLSX.Core
masterNanoXLSX.Core is the foundational component of the NanoXLSX library. It provides the core logic required to manipulate workbooks, worksheets, cells, and styles in the XLSX format.
Important: This package is a logic-only library; it does not handle the actual reading or writing of files to disk. To perform file I/O, you must use additional plugin packages that depend on NanoXLSX.Core.
Migrate ImportOptions to ReaderOptions in v3.0.0
masterThe
ImportOptionsclass has been renamed toReaderOptions. When migrating to v3.0.0, update your code to use the new class name and note the following changes to constants and methods:Renamed Constants
Old ImportOptions Constant New ReaderOptions Constant DEFAULT_TIMESPAN_FORMATDefaultTimeSpanFormatDEFAULT_DATETIME_FORMATDefaultDateTimeFormatRenamed Methods
Old method name New method name EnforceValidColumnDimensionsEnforceStrictValidationEnforceValidRowDimensionsEnforceStrictValidationRemoved Enum Values
ImportOptions.GlobalType.AllSingleToDecimalhas been removed.- Replacement: Use
ReaderOptions.GlobalType.AllNumbersToDecimalif the same behavior is required.
Migrate internal reader namespaces in v3.0.0
masterIf your code directly uses internal reader classes, you must update the namespace. All internal reader classes have moved from
NanoXLSX.LowLeveltoNanoXLSX.Internal.Readers.Warning: The architecture of these internal classes was redesigned from scratch in v3.0.0. If you have custom modifications to these classes, they will likely need to be redone.
Recommended approach: Instead of modifying internal classes, use the introduced plugin architecture to implement custom readers that can replace or append to existing readers during the read process.
Migrate from NanoXLSX v2.x to v3.0.0
masterNanoXLSX v3.0.0 introduced breaking changes to improve usability, consistency, and modularization. The most significant change is the modularization of the library into three distinct packages:
NanoXLSX.Core: Contains core classes such asWorkbook,Worksheet,Cell, andStyle.NanoXLSX.Reader: Contains all reading functionalities.NanoXLSX.Writer: Contains all writing functionalities.
When migrating, you must update your project references to include the specific package required for your task (reading or writing) instead of relying on a single monolithic package. Additionally, you may need to update namespaces (e.g., adding
using NanoXLSX.Extensions;for reader extension methods) and adapt to renamed constants that now follow standard C# naming conventions.// Example of updated namespace usage for reader extensions using NanoXLSX.Extensions;Install NanoXLSX via NuGet
masterThe recommended way to install NanoXLSX is using NuGet. You can install the meta-package
NanoXLSX, which bundles all modules (Core, Reader, Writer, Formatting, and Compatibility), or install specific modules individually for advanced scenarios (e.g.,NanoXLSX.Core+NanoXLSX.Writerfor write-only applications).Use the Package Manager or .NET CLI to install the full bundle.
# By Package Manager (PM) Install-Package NanoXLSX # By .NET CLI dotnet add package NanoXLSXMigrate Fill usage from v2.x to v3.0.0
masterThe
Fillclass was overhauled to support flexible color definitions (ARGB, indexed, theme, or system colors).- Color Properties:
Fill.BackgroundColorandFill.ForegroundColorare now theColorclass instead ofstring. - Indexed Colors: The
IndexedColorproperty was removed. Use theColorclass withIndexedColor.Valueenum or integer indices. - Renamed Members: Constants and enums were renamed to PascalCase (e.g.,
FillType.patternColor$\rightarrow$FillType.PatternColor). - Validation:
Fill.ValidateColr(string, bool, bool)moved toNanoXLSX.Utils.Validators.ValidateColr(string, bool, bool).
Fill fill = new Fill(); fill.ForegroundColor = Color.CreateIndexed(IndexedColor.Value.Yellow); // ARGB Fill fill2 = new Fill(); fill2.BackgroundColor = Color.CreateRgb("FF00FF00"); // Theme color with tint Fill fill3 = new Fill(); fill3.ForegroundColor = Color.CreateTheme(Theme.ColorSchemeElement.Accent1, 0.5f); // Implicit conversions Fill fill4 = "FF00FF00"; // Implicit SrgbColor Fill fill5 = IndexedColor.Value.Red2; // Implicit IndexedColor Fill fill6 = 64; // Implicit IndexedColor via index number- Color Properties:
Install the NanoXLSX meta package
masterThe
NanoXLSXmeta package is the recommended way to install the library as it automatically includes the necessary dependencies for a full feature set. Installing this package provides access to core workbook operations, reading, writing, and cell formatting.# Use NuGet to install the meta package dotnet add package NanoXLSXMigrate Workbook usage from v2.x to v3.0.0
masterIn version 3.0.0, the
Workbookclass underwent modularization.- Loading Workbooks:
Workbook.Load(...)andWorkbook.LoadAsync(...)have been removed. Use the Reader module instead. - Style Management:
Workbook.AddStyle(Style)andWorkbook.AddStyleComponent(Style, AbstractStyle)are removed. Apply styles directly to cells or ranges. - Removing Styles:
Workbook.RemoveStyle(...)methods are removed. Usecell.RemoveStyle()instead. - Colors:
Workbook.GetMruColors()now returnsIReadOnlyList<Color>instead ofstring. The newColorclass (namespaceNanoXLSX.Colors) supports RGB, ARGB, system, theme, or indexed colors.
// Old way (removed): // workbook.AddStyle(myStyle); // New way: workbook.CurrentWorksheet.Cells["A1"].CellStyle.CurrentFont.Bold = true; // OR workbook.CurrentWorksheet.Cells["A1"].CellStyle.Append(fontStyle);- Loading Workbooks: