Lay.KH.ExcelExporter 1.3.0

dotnet add package Lay.KH.ExcelExporter --version 1.3.0
                    
NuGet\Install-Package Lay.KH.ExcelExporter -Version 1.3.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="Lay.KH.ExcelExporter" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lay.KH.ExcelExporter" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Lay.KH.ExcelExporter" />
                    
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 Lay.KH.ExcelExporter --version 1.3.0
                    
#r "nuget: Lay.KH.ExcelExporter, 1.3.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 Lay.KH.ExcelExporter@1.3.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=Lay.KH.ExcelExporter&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Lay.KH.ExcelExporter&version=1.3.0
                    
Install as a Cake Tool

📊 Excel Exporter 📊

📧 Email: lylay.it.kh855@gmail.com
📞 Phone: +855 10 657 986
🔗 LinkedIn: Ly Lay


Quick Access


Overview ▲

The Excel Exporter provides extension methods for exporting collections of objects (arrays, lists, and enumerables) to Excel files.
It supports output as byte arrays, memory streams, or direct file saves, with customization via attributes and export options.


Feature ▲

Function Description
📊 Export to Byte Array Convert collections to Excel and return as byte[].
💾 Export to Stream Generate Excel content as MemoryStream for further processing.
📂 Save to File Write Excel files directly to disk with overwrite support.
📑 Multi-Sheet Export Export multiple collections into separate worksheets.
🏷️ Attribute Customization Use [ExcelIgnore] and [ExcelColumn] for property-level control.
📐 Auto Column Adjustment Automatically adjusts column widths to fit content.
⚙️ Export Options Configure headers, formatting, freezing rows, and more.

Installation ▲

Using .NET CLI

dotnet add package Lay.KH.ExcelExporter

Using Package Manager Console

Install-Package Lay.KH.ExcelExporter

Configuration ▲

To use the Excel Exporter:

  1. Default Worksheet Name: "Sheet1" if none specified.
  2. Attributes:
    • [ExcelIgnore] → exclude property from export.
    • [ExcelColumn("CustomName")] → rename column header.
  3. Export Options:
    • Bold headers
    • Freeze header rows
    • Auto-adjust column widths

Example ▲

// Employee model with attributes
public class Employee
{
    [ExcelColumn("Employee ID")]
    public int Id { get; set; }

    public string Name { get; set; }

    [ExcelIgnore] // Exclude from export
    public string InternalCode { get; set; }

    [ExcelColumn("Joining Date")]
    public DateTime HireDate { get; set; }
}

var employees = new List<Employee>
{
    new Employee { Id = 1, Name = "Alice", InternalCode = "X123", HireDate = DateTime.Now },
    new Employee { Id = 2, Name = "Bob", InternalCode = "Y456", HireDate = DateTime.Now }
};

// 1. Export to byte array
byte[] excelBytes = employees.ToExcelBytes("Employees");

// 2. Export to MemoryStream
using var stream = employees.ToExcelStream("Employees");
using var file = File.Create("employees_stream.xlsx");
stream.CopyTo(file);

// 3. Save directly to file with options
var options = new ExcelExportOptions
{
    BoldHeaders = true,
    FreezeHeaderRow = true,
    AutoFitColumns = true
};
employees.SaveAsExcel("employees_with_options.xlsx", options);

// 4. Multi-sheet export
var sheets = new Dictionary<string, IEnumerable<object>>
{
    { "Employees", employees },
    { "Departments", new List<object> { new { Id = 1, Name = "HR" }, new { Id = 2, Name = "IT" } } }
};
sheets.SaveAsExcelMultiSheet("company.xlsx");

// 5. Multi-sheet export to byte array
var multiSheetBytes = sheets.ToExcelMultiSheetBytes();
File.WriteAllBytes("company_bytes.xlsx", multiSheetBytes);

// 6. Product model with attributes
public class Product
{
    [ExcelColumn("Product Code")]
    public string Code { get; set; }

    [ExcelColumn("Product Name")]
    public string Name { get; set; }

    [ExcelIgnore] // Hide sensitive info
    public decimal CostPrice { get; set; }

    [ExcelColumn("Sale Price")]
    public decimal SalePrice { get; set; }

    [ExcelColumn("Available Stock")]
    public int Stock { get; set; }
}

var products = new List<Product>
{
    new Product { Code = "P001", Name = "Laptop", CostPrice = 500, SalePrice = 700, Stock = 20 },
    new Product { Code = "P002", Name = "Mouse", CostPrice = 10, SalePrice = 15, Stock = 100 }
};

// Export product list with custom headers applied
products.SaveAsExcel("products.xlsx", "Products");

// 7. Using IEnumerable<T> directly
IEnumerable<Employee> employeeEnumerable = employees;
employeeEnumerable.SaveAsExcel("employees_enumerable.xlsx", "Employees");
byte[] enumerableBytes = employeeEnumerable.ToExcelBytes("Employees");
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

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.3.0 220 3/20/2026
1.1.0 123 2/15/2026
1.0.0 129 2/14/2026

Initial release: single-sheet, multi-sheet, attribute support, page setup.