IowaComputerGurus / netcore.utilities.spreadsheet

A utility to assist in creating Excel spreadsheets in .NET 6+ applications
MIT License
22 stars 3 forks source link
aspnetcore c-sharp dotnet-core excel excel-export hacktoberfest spreadsheet

NetCore.Utilities.Spreadsheet

Build Status

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

NuGet Package Information

ICG.NetCore.Utilities.Spreadsheet

SonarCloud Analysis

Quality Gate Status Coverage Security Rating Technical Debt

Dependencies

This project depends on the DocumentFormat.OpenXml NuGet package provided by the Microsoft team. It is a MIT licensed library.

Usage

Installation

Standard installation via NuGet Package Manager

Install-Package ICG.NetCore.Utilities.Spreadsheet

Setup

To setup the needed dependency injection items for this library, add the following line in your DI setup.

services.UseIcgNetCoreUtilitiesSpreadsheet();

Sample Single Document Export

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);

Sample Multi-Sheet Document Export

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);

Key Features

This package is primarily geared towards the exporting of lists of objects into excel sheets. The following key features are supported.