Zeyt.ExcelDocument
1.0.1
See the version list below for details.
dotnet add package Zeyt.ExcelDocument --version 1.0.1
NuGet\Install-Package Zeyt.ExcelDocument -Version 1.0.1
<PackageReference Include="Zeyt.ExcelDocument" Version="1.0.1" />
paket add Zeyt.ExcelDocument --version 1.0.1
#r "nuget: Zeyt.ExcelDocument, 1.0.1"
// Install Zeyt.ExcelDocument as a Cake Addin #addin nuget:?package=Zeyt.ExcelDocument&version=1.0.1 // Install Zeyt.ExcelDocument as a Cake Tool #tool nuget:?package=Zeyt.ExcelDocument&version=1.0.1
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 | Versions 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. |
-
net6.0
- SpreadCheetah (>= 1.17.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release