https://github.com/zeytdev/zeyt.exceldocument
Zeyt.ExcelDocument is a C# library that simplifies the creation of Excel documents from object lists. It provides an intuitive API to map object properties to Excel columns, allowing for custom column names, widths, and default values for null fields.
https://github.com/zeytdev/zeyt.exceldocument
csharp dotnet excel exceldocument xslx
Last synced: 5 months ago
JSON representation
Zeyt.ExcelDocument is a C# library that simplifies the creation of Excel documents from object lists. It provides an intuitive API to map object properties to Excel columns, allowing for custom column names, widths, and default values for null fields.
- Host: GitHub
- URL: https://github.com/zeytdev/zeyt.exceldocument
- Owner: zeytdev
- License: mit
- Created: 2024-09-09T16:03:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-22T17:33:04.000Z (almost 2 years ago)
- Last Synced: 2025-10-03T12:39:05.274Z (10 months ago)
- Topics: csharp, dotnet, excel, exceldocument, xslx
- Language: C#
- Homepage:
- Size: 2.64 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zeyt.ExcelDocument
[](https://www.nuget.org/packages/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:
```bash
Install-Package Zeyt.ExcelDocument
```
Or via .NET CLI:
```bash
dotnet add package Zeyt.ExcelDocument
```
## Example Usage
Here is a basic example of how to use the **Zeyt.ExcelDocument** library:
```csharp
using Zeyt.ExcelDocument;
var customerList = new List
{
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 Information").Write(customerList);
File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Customer.xlsx"), customerExcelData);
```
### Mapping Configuration
The mapping is done using a separate `ExcelDocumentMap` class. In this example, we create a custom mapping for the `Customer` class:
```csharp
public class CustomerExcelMap : ExcelDocumentMap
{
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:
```csharp
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](LICENSE) file for details.
---