Goffo.ExcelExport 1.1.0

dotnet add package Goffo.ExcelExport --version 1.1.0                
NuGet\Install-Package Goffo.ExcelExport -Version 1.1.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="Goffo.ExcelExport" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Goffo.ExcelExport --version 1.1.0                
#r "nuget: Goffo.ExcelExport, 1.1.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 Goffo.ExcelExport as a Cake Addin
#addin nuget:?package=Goffo.ExcelExport&version=1.1.0

// Install Goffo.ExcelExport as a Cake Tool
#tool nuget:?package=Goffo.ExcelExport&version=1.1.0                

Excel Export

This uses the ClosedXML library. It allows for quick export of an IEnumerable of an generic class type to an excel file and is also able to do multiple sheets. Sheet names can be provided. Column headers can be specified using the DisplayName attribute from System.ComponentModel.

Code Examples

using ExcelExport.Services;
using System.ComponentModel;

//Create a new service
IExcelExportService _service = new ExcelExportService();

//Data Setup
List<PersonModel> PeopleList = new List<PersonModel>
{
    new PersonModel{ FirstName = "John", LastName = "Doe", Email = "johndoe@gmail.com" },
    new PersonModel{ FirstName = "Jane", LastName = "Doe", Email = "janedoe@gmail.com" },
};

List<AnimalModel> AnimalList = new List<AnimalModel>
{
    new AnimalModel{ CommonName = "Tiger", IsExtinct = false },
    new AnimalModel{ CommonName = "Dodo Bird", IsExtinct = true },
    new AnimalModel{ CommonName = "Zebra", IsExtinct = false }
};

//Define Sheet Names
string excelSheetName = "List of People";

//Single Sheet as Byte Array
byte[] ExcelBytes = await _service.ExcelExportAsByteArrayAsync(PeopleList, excelSheetName);

//Do something with your byte array...
Console.WriteLine(ExcelBytes.Length);

//Multiple Sheets as Byte Array
//Initialize and then Add 
_service.InitializeExcelDataSheets();
_service.AddExcelDataSheet(PeopleList, "List of People");
_service.AddExcelDataSheet(AnimalList, "List of Animals");
ExcelBytes = await _service.ExcelExportMultiSheetAsByteArrayAsync();

//Do something with your byte array...
Console.WriteLine(ExcelBytes.Length);


//Set File
string file = @$"C:\Users\{Environment.UserName}\MyExcelFile.xlsx";

//Single Sheet as File
await _service.ExcelExportAsFileAsync(PeopleList, file, excelSheetName);

Console.WriteLine("Excel file created: {0}", file);

//Multiple Sheets as File
file = @$"C:\Users\{Environment.UserName}\MyExcelMulitSheetFile.xlsx";

//Initialize and then Add 
_service.InitializeExcelDataSheets();
_service.AddExcelDataSheet(PeopleList, "List of People");
_service.AddExcelDataSheet(AnimalList, "List of Animals");

await _service.ExcelExportMultiSheetAsFileAsync(file);

Console.WriteLine("Excel file created: {0}", file);

internal class PersonModel
{
    //Column Header will use Display Name Attribute if set
    [DisplayName("First Name")]
    public string FirstName { get; set; } = string.Empty;

    [DisplayName("Last Name")]
    public string LastName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;

}

internal class AnimalModel
{
    [DisplayName("Common Name")]
    public string CommonName { get; set; } = string.Empty;

    [DisplayName("Extinct")]
    public bool IsExtinct { get; set; }
}
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 is compatible.  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 is compatible.  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.

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.1.0 139 2/22/2024
1.0.0 155 1/17/2024

MemoryStream now properly being disposed.