Codebrew.ExcelAnnotations 2.0.1

dotnet add package Codebrew.ExcelAnnotations --version 2.0.1
                    
NuGet\Install-Package Codebrew.ExcelAnnotations -Version 2.0.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="Codebrew.ExcelAnnotations" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Codebrew.ExcelAnnotations" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Codebrew.ExcelAnnotations" />
                    
Project file
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 Codebrew.ExcelAnnotations --version 2.0.1
                    
#r "nuget: Codebrew.ExcelAnnotations, 2.0.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 Codebrew.ExcelAnnotations@2.0.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=Codebrew.ExcelAnnotations&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Codebrew.ExcelAnnotations&version=2.0.1
                    
Install as a Cake Tool

Codebrew.ExcelAnnotations

Codebrew.ExcelAnnotations is a robust and extensible C# library that streamlines the process of importing and exporting Excel files (.xlsx) using attribute-based configurations. Inspired by ORM frameworks like Entity Framework, it offers a fluent and customizable approach to map objects to Excel sheets and vice versa.


โœจ Features

  • ๐Ÿ“… Import Excel files directly into strongly-typed models using attribute-based mapping.
  • ๐Ÿ“„ Export models into styled Excel spreadsheets with full control via annotations and theming.
  • ๐ŸŽจ Custom themes and styles using abstract base classes and reflection.
  • ๐Ÿ”„ Support for custom value converters through interfaces.
  • ๐Ÿงน Extendable with your own attributes or behaviors.

๐Ÿ“ฆ Installation

Install the package via NuGet:

dotnet add package Codebrew.ExcelAnnotations

๐Ÿš€ Getting Started

Define a model with attributes

[WorksheetName("Product")]
public class Product
{
    [Header("Id")]
    public int Id { get; set; }

    [Header("Name", typeof(HeaderTheme))] //overwrite the default theme for header with your custom theme
    public string Name { get; set; }

    [Header("Price")]
    public decimal Price { get; set; }

    [Header("Expiration Date")]
    [DateTimeFormatter] //create custom formatters
    public DateTime? ExpirationDate { get; set; }

    [Header("Is Active")]
    [BoolConverter(["Yes"], ["No"])]
    public bool? IsActive { get; set; }

    [Header("Avalable Percentage")]
    [PercentageConverter]
    public decimal AvalablePercentage { get; set; }
}

Import from Excel

using(var importer = new Importer("excel.xlsx"))
{
    return importer.Import<T>(new WorksheetOptions()).ToList();
}

Export to Excel


using (var exporter = new Exporter())
{
    exporter.MapToWorksheet(items, new WorksheetOptions());
    exporter.MapToWorksheet(items, new WorksheetOptions() { WorksheetName = "Compare with exported" }); //can map other worksheet, forcing worksheetName on options
    exporter.ExportToPath("excel.xlsx"); // or exporter.ToStream()
}

๐ŸŽจ Custom Themes

Create custom themes by inheriting from ThemeBase:

public class MyCustomTheme : ThemeBase<MyCustomTheme>
{
    public MyCustomTheme()
    {
        FontBold = true;
        FontItalic = false;
        FontFamily = "Verdana";
        FontSize = 10;
        FontColor = ThemeColors.Text_White;
        BackgroundColor = ThemeColors.Accent1_Blue_Dark;
    }
}

Assign this theme in the export options to apply consistent styling.


๐Ÿง Advanced Features

  • Dynamic Property Mapping: Use [Header("Column Name")] to bind properties to spreadsheet columns.
  • Cell Value Conversion: Implement IConvertCellValue to define custom parsing from cell to property.
  • Conditional Styling: Apply styles through theming or directly via attributes.
  • Concurrent-Safe Parsing: The engine supports safe reflection and data handling with customization flexibility.

๐Ÿงช Example Usage

Refer to the Example project to see the library in action with various models and customizations.


๐Ÿ’ช Roadmap

  • Localization support for headers.
  • Multiple sheet exports.
  • Enhanced formula and conditional formatting support.

๐Ÿค Contributing

Contributions are welcome! Feel free to open issues or submit pull requests with improvements. Ideas for new attributes, better export settings, or utility features are always appreciated.


๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


๐Ÿ‘จโ€๐Ÿ’ป Author

Developed with โ˜• by @fogacafe

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 231 5/15/2025
2.0.0 229 5/14/2025
1.0.0 74 5/3/2025