Codebrew.ExcelAnnotations
2.0.1
dotnet add package Codebrew.ExcelAnnotations --version 2.0.1
NuGet\Install-Package Codebrew.ExcelAnnotations -Version 2.0.1
<PackageReference Include="Codebrew.ExcelAnnotations" Version="2.0.1" />
<PackageVersion Include="Codebrew.ExcelAnnotations" Version="2.0.1" />
<PackageReference Include="Codebrew.ExcelAnnotations" />
paket add Codebrew.ExcelAnnotations --version 2.0.1
#r "nuget: Codebrew.ExcelAnnotations, 2.0.1"
#:package Codebrew.ExcelAnnotations@2.0.1
#addin nuget:?package=Codebrew.ExcelAnnotations&version=2.0.1
#tool nuget:?package=Codebrew.ExcelAnnotations&version=2.0.1
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 | Versions 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. |
-
.NETStandard 2.1
- ClosedXML (>= 0.104.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.