A utility to assist in creating Excel spreadsheets in .NET Core and ASP.NET Core applications using the OpenXML library. This utility allows you to export collections of .NET Objects to Excel by simply adding metadata information regarding the desired column formats, title etc. Allowing quick & consistent excel exports, without the hassle of trying to understand the OpenXML format
ICG.NetCore.Utilities.Spreadsheet
This project depends on the DocumentFormat.OpenXml NuGet package provided by the Microsoft team. It is a MIT licensed library.
Standard installation via NuGet Package Manager
Install-Package ICG.NetCore.Utilities.Spreadsheet
To setup the needed dependency injection items for this library, add the following line in your DI setup.
services.UseIcgNetCoreUtilitiesSpreadsheet();
Exporting a single collection to a single excel file can be done very simply.
var exportGenerator = provider.GetService<ISpreadsheetGenerator>();
var exportDefinition = new SpreadsheetConfiguration<SimpleExportData>
{
RenderTitle = true,
DocumentTitle = "Sample Export of 100 Records",
RenderSubTitle = true,
DocumentSubTitle = "Showing the full options",
ExportData = GetSampleExportData(100),
WorksheetName = "Sample",
FreezePanes = true,
AutoFilterDataRows = true
};
var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);
System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);
A streamlined fluent syntax is available to export multiple sheets of content.
var multiSheetDefinition = new MultisheetConfiguration()
.WithSheet("Sheet 1", GetSampleExportData(100))
.WithSheet("Additional Sheet", GetSampleExportData(500), config =>
{
config.DocumentTitle = "Lots of data";
config.RenderTitle = true;
});
var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheetDefinition);
System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
This package is primarily geared towards the exporting of lists of objects into excel sheets. The following key features are supported.