Gufel.ExcelBuilder.Model 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Gufel.ExcelBuilder.Model --version 1.0.0
                    
NuGet\Install-Package Gufel.ExcelBuilder.Model -Version 1.0.0
                    
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="Gufel.ExcelBuilder.Model" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gufel.ExcelBuilder.Model" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Gufel.ExcelBuilder.Model" />
                    
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 Gufel.ExcelBuilder.Model --version 1.0.0
                    
#r "nuget: Gufel.ExcelBuilder.Model, 1.0.0"
                    
#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 Gufel.ExcelBuilder.Model@1.0.0
                    
#: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=Gufel.ExcelBuilder.Model&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Gufel.ExcelBuilder.Model&version=1.0.0
                    
Install as a Cake Tool

Gufel.ExcelBuilder.Model

This project provides a flexible and extensible framework for building and exporting Excel files in .NET, with a focus on customizable column and value handling. It is designed to be used as the model layer for the Gufel.ExcelBuilder library.

Key Components

1. ExcelBuilder Base Class

The ExcelBuilder class (located in the main project, not this model subfolder) is the core class responsible for creating and managing Excel files. It provides methods to:

  • Add sheets from generic data collections.
  • Customize column and value providers.
  • Apply styles and formatting.
  • Handle events for worksheet and column creation, and custom rendering.
Example Usage
var builder = new ExcelBuilder();
builder.AddSheet("Sheet1", myDataList);
byte[] fileBytes = builder.BuildFile();

2. Interfaces

IColumnProvider

Located in Model/Base/IColumnProvider.cs, this interface abstracts how column metadata is provided to the builder.

public interface IColumnProvider
{
    void SetSampleData(object? sampleData);
    List<ExcelColumnAttribute> GetColumns(Type dataType);
}
  • SetSampleData: Allows the provider to inspect a sample object for dynamic column inference.
  • GetColumns: Returns a list of ExcelColumnAttribute objects describing the columns for a given data type.
IValueProvider

Located in Model/Base/IValueProvider.cs, this interface abstracts how values are extracted from data objects for each column.

public interface IValueProvider
{
    object? GetValue(ExcelColumnAttribute excelColumn, object classObject);
    Dictionary<string, object?> GetValues(List<ExcelColumnAttribute> excelColumns, object classObject);
}
  • GetValue: Extracts a single value for a column from a data object.
  • GetValues: Extracts all column values from a data object as a dictionary.

3. Attributes and Formats

ExcelColumnAttribute

Located in Model/ExcelColumnAttribute.cs, this attribute is used to annotate properties or fields in your data models to control how they are exported to Excel.

Key properties:

  • Name: The column name in Excel.
  • HasValue: Whether the column should be populated from the data source.
  • AsPersianDate: Whether to convert dates to Persian format.
  • PersianDateFormat: Custom format for Persian dates.
  • ColumnFormat: Excel number format string.
  • SourceName: The source property/field name in the data object.
  • Priority: Order of the column.
  • SourceIsField: Whether the source is a field (vs. property).
ExcelColumnFormat

Located in Model/ExcelColumnFormat.cs, this static class provides common Excel number format strings for convenience, such as:

  • OneDecimalPlace
  • TwoDecimalPlace
  • Percent
  • ThousandSeparator
  • NegativeRed

Extensibility

You can implement your own IColumnProvider or IValueProvider to customize how columns and values are determined and rendered in the Excel output.

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Gufel.ExcelBuilder.Model:

Package Downloads
Gufel.ExcelBuilder

This project provides a flexible and extensible framework for building and exporting Excel files in .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 150 7/8/2025
2.0.0 150 7/8/2025
1.0.0 154 6/17/2025