Zeyt.ExcelDocument 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zeyt.ExcelDocument --version 1.0.0                
NuGet\Install-Package Zeyt.ExcelDocument -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="Zeyt.ExcelDocument" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zeyt.ExcelDocument --version 1.0.0                
#r "nuget: Zeyt.ExcelDocument, 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.
// Install Zeyt.ExcelDocument as a Cake Addin
#addin nuget:?package=Zeyt.ExcelDocument&version=1.0.0

// Install Zeyt.ExcelDocument as a Cake Tool
#tool nuget:?package=Zeyt.ExcelDocument&version=1.0.0                

Zeyt.ExcelDocument

Zeyt.ExcelDocument is a powerful and easy-to-use C# library designed for generating Excel documents from object lists. The library allows you to map object properties to Excel columns with custom names, widths, and even default values for fields with missing data. It also provides an easy way to export this data to .xlsx format.

Features

  • Customizable Mappings: Easily map object properties to Excel columns.
  • Fluent API: Set column names, widths, and default values for null fields.
  • Quick Export: Convert object lists into Excel files in just a few lines of code.
  • Null Field Handling: Define default values for fields with missing data.

Installation

You can install the package via NuGet Package Manager:

Install-Package Zeyt.ExcelDocument

Or via .NET CLI:

dotnet add package Zeyt.ExcelDocument

Example Usage

Here is a basic example of how to use the Zeyt.ExcelDocument library:

using Zeyt.ExcelDocument;

var customerList = new List<Customer>
{
    new Customer { FirstName = "James", LastName = "Butt", Age = 23, Email = "james@james.com" },
    new Customer { FirstName = "Art", LastName = "Venere", Age = 33, Email = "art@venere.com" },
    new Customer { FirstName = "Sage", LastName = "Wieser", Age = 57, Email = null },
    new Customer { FirstName = "Minna", LastName = "Amigon", Age = 45, Email = "minna@amigon.com" },
    new Customer { FirstName = "Blair", LastName = "Malet", Age = 66, Email = null },
};

// Map customer data to Excel and export it to a file
var customerExcelData = new ExcelDocumentWriter<Customer, CustomerExcelMap>("Customer Information").Write(customerList);
File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Customer.xlsx"), customerExcelData);

Mapping Configuration

The mapping is done using a separate ExcelDocumentMap<T> class. In this example, we create a custom mapping for the Customer class:

public class CustomerExcelMap : ExcelDocumentMap<Customer>
{
    public CustomerExcelMap()
    {
        Map(x => x.FirstName).Name("Full Name").Width(30).WriteUsing(x => $"{x.FirstName} {x.LastName}");
        Map(x => x.Age).Name("Age").Width(10);
        Map(x => x.Email).Name("Email").Width(50).Default("EMPTY");
    }
}

The Customer Class

This is the class we are mapping to Excel columns:

public class Customer
{
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
    public int? Age { get; set; } = 0;
    public string? Email { get; set; }
}

License

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


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

This package has no dependencies.

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
1.0.2 93 9/22/2024
1.0.1 111 9/10/2024
1.0.0 106 9/10/2024

Initial release