TemplateExport.Excel 0.1.3

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

TemplateExport.Excel

TemplateExport.Excel is a library for exporting Excel documents using templates. It allows you to define templates with placeholders and dynamically replace them with data.

Features

  • Load Excel templates from files
  • Replace placeholders with data
  • Support for conditional rendering
  • Support for lists and collections

Installation

To install TemplateExport.Excel, add the following NuGet package to your project:

dotnet add package TemplateExport.Excel

Usage

1. Configure Services

First, configure the services in your Main function or startup class:

using Microsoft.Extensions.DependencyInjection;
using TemplateExport.Excel.Extensions;

var services = new ServiceCollection();
services.AddTemplateExportExcel();
var serviceProvider = services.BuildServiceProvider();

2. Create excel template on given location

Create template xlsx file on location provided to configuration builder template-example.xlsx

3. Create an Excel Export Configuration

Create a configuration for exporting an Excel document:

using TemplateExport.Excel.Models;

var config = ExcelExportConfiguration.CreateBuilder()
    .UseTemplatePath("./Resources/template.xlsx")
    .UseOutputPath("./Resources/output.xlsx")
    .AddDataSet("Person", new Person { Name = "John", Age = 30 })
    .Build();

4. Export the Excel

Resolve the ITemplateExportExcel service and call the Export method:

var excelExport = serviceProvider.GetService<ITemplateExportExcel>();
excelExport.Export(config);

5. Configuration options


UseOutputStream(stream) // set output stream for excel

UseTemplateStringStartsWith("{{") // set placeholders starts with string (Default: "{{")

UseTemplateStringEndsWith("}}") // set placeholders starts with string (Default: "}}")

UseTemplateStringSeparator("::") // set placeholders separator string (Default: "::")

EnablePreserveRowHeight(false) // preserve row height of template file. Can be very slow for a lot of rows (Default: true)

EnablePreserveColumnWidth(false) // preserve column width of template file. Can be very slow for a lot of columns (Default: true)

EnablePreserveMergeCells(false) // preserve merge cells of template file. Can be very slow for a lot of merge cells (Default: true)

EnablePreserveCellStyles(false) // preserve cell styles of template file. Can be very slow for a lot of cells (Default: true)

EnableAutoFitColumns(true) // auto fit columns after export. Cannot be true if PreserveColumnWidth is enabled (Default: false)

EnableAutoFitRows(true) // auto fit rows after export. Cannot be true if PreserveRowHeight is enabled (Default: false)

AddDataSet("Person", new Person { Name = "John", Age = 30 }) // add data set to configuration

6. Charts

TemplateExport.Excel supports charts. Just create template with chart referencing cells with placeholders.


var config = ExcelExportConfiguration.CreateBuilder()
        .UseTemplatePath("./Resources/chart.xlsx")
        .UseOutputPath("./Resources/chartOutput.xlsx")
        .AddDataSet("aaa", 2)
        .AddDataSet("bbb", 3)
        .EnableCopyGraphs()
        .Build();
templateExportExcel.Export(config);

Example

Here is a complete example of exporting an Excel document:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using TemplateExport.Excel;
using TemplateExport.Excel.Extensions;
using TemplateExport.Excel.Models;

var services = new ServiceCollection();
services.AddTemplateExportExcel();
var serviceProvider = services.BuildServiceProvider();

var excelExport = serviceProvider.GetService<ITemplateExportExcel>();

var person = new Person { Name = "John", Age = 30 };
var people = new List<Person>
{
    new Person { Name = "Alice", Age = 25 },
    new Person { Name = "Bob", Age = 35 }
};

var config = ExcelExportConfiguration.CreateBuilder()
    .UseTemplatePath("./Resources/template.xlsx")
    .UseOutputPath("./Resources/output.xlsx")
    .AddDataSet("Person", person)
    .AddDataSet("People", people)
    .Build();

var stopwatch = new Stopwatch();
stopwatch.Start();

excelExport.Export(config);

stopwatch.Stop();
Console.WriteLine($"Elapsed time: {stopwatch.ElapsedMilliseconds} ms");

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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
0.1.3 88 7/2/2026
0.1.2 848 3/25/2025
0.1.1 483 3/25/2025
0.1.0 436 3/24/2025
0.0.7 229 3/18/2025
0.0.6 203 3/18/2025
0.0.5 191 3/14/2025
0.0.4 297 3/5/2025
0.0.3 277 3/5/2025
0.0.2 272 3/5/2025
0.0.1 252 3/3/2025