TPJ.Excel 10.0.0

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

TPJ.Excel

TPJ.Excel is a small helper library for generating Excel files in three different ways:

  1. ExcelDocument for quick exports from a list, DataTable, or DataSet
  2. EPPlusHelper when you want custom headers and simple formatting
  3. AddWorksheet / ExcelWorksheetExtension when you want full control while still writing concise EPPlus code

If you want to see working examples, check TPJ.ExcelTest.

When to use each option

Use ExcelDocument when you want speed and simplicity

  • Create a workbook directly from a List<T>, DataTable, or DataSet
  • Column names come from property names or table columns
  • Good for quick exports where default formatting is enough

Use EPPlusHelper when you want clean control over output

  • Set worksheet names
  • Choose your own headers
  • Format dates and numbers
  • Good for most business export scenarios

Use full EPPlus support when you need custom layout

  • Write exactly where you want in the sheet
  • Move cell by cell using CurrentCell(), NextColumn(), and NextRow()
  • Good for reports, grouped sections, totals, and custom styling

Sample model

All examples below use this simple model:

public class Staff
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public DateTime StartDate { get; set; }
    public decimal Salary { get; set; }
}

var staff = new List<Staff>
{
    new() { Id = 1, Name = "Jeff Bob", StartDate = new DateTime(2024, 1, 15), Salary = 32500m },
    new() { Id = 2, Name = "Thomas James", StartDate = new DateTime(2022, 6, 1), Salary = 41000m },
    new() { Id = 3, Name = "Sophie Hall", StartDate = new DateTime(2025, 2, 10), Salary = 29500m }
};

1. Quick export with ExcelDocument

ExcelDocument is the quickest way to generate an Excel file.

Save a list to disk

using TPJ.Excel;

ExcelDocument.Create(staff, @"C:\Test\Staff.xlsx");

You can also pass any IEnumerable<T> and choose the worksheet name:

using TPJ.Excel;

ExcelDocument.Create(staff.Where(x => x.Salary >= 30000m), @"C:\Test\StaffFiltered.xlsx", "Staff");

Return the file as bytes

using TPJ.Excel;

byte[] excelBytes = ExcelDocument.Create(staff);

Notes

  • Each public property becomes a column
  • Property names are used as the header row
  • Simple scalar values such as string, int, decimal, and DateTime are exported as a single Value column
  • You can also create files from DataTable and DataSet

Example with a DataTable:

using System.Data;
using TPJ.Excel;

var table = new DataTable("Staff");
table.Columns.Add("Staff #", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Start Date", typeof(DateTime));

table.Rows.Add(1, "Jeff Bob", new DateTime(2024, 1, 15));
table.Rows.Add(2, "Thomas James", new DateTime(2022, 6, 1));

ExcelDocument.Create(table, @"C:\Test\StaffFromTable.xlsx");

2. Custom headers and formatting with EPPlusHelper

Use EPPlusHelper when you want a simple API but need more control over how the sheet looks.

Main types

For most cases, use the typed builder overloads:

using TPJ.Excel;

EPPlusHelper.Create(
    staff,
    "Staff",
    @"C:\Test\StaffFormatted.xlsx",
    columns => columns
        .Add("Staff #", x => x.Id)
        .Add("Name", x => x.Name)
        .Add("Start Date", x => x.StartDate, dateFormat: "dd/mm/yyyy")
        .Add("Salary", x => x.Salary, numberFormat: "#,##0.00"));

You can still use EPPlusHelper.Column<T>(...) if you prefer building the column list yourself.

If you want to build multiple typed worksheets before creating the workbook, use EPPlusHelper.Worksheet(...):

using TPJ.Excel;

var summarySheet = EPPlusHelper.Worksheet(
    staff.Select(x => new { Label = x.Name, Created = DateTime.Today }),
    "Summary",
    columns => columns
        .Add("Label", x => x.Label)
        .Add("Created", x => x.Created, dateFormat: "dd/mm/yyyy"));

var staffSheet = EPPlusHelper.Worksheet(
    staff,
    "Staff",
    columns => columns
        .Add("Staff #", x => x.Id)
        .Add("Name", x => x.Name)
        .Add("Start Date", x => x.StartDate, dateFormat: "dd/mm/yyyy")
        .Add("Salary", x => x.Salary, numberFormat: "#,##0.00"));

EPPlusHelper.Create(new[] { summarySheet, staffSheet }, @"C:\Test\StaffReport.xlsx");

If you want to build the worksheet model yourself, these are the core types:

  • EPPlusWorksheet
    • Name: worksheet name
    • Headers: column headers
    • Rows: row data
  • EPPlusRow
    • Data: the cells for that row, in column order
  • EPPlusData
    • Value: cell value
    • DateFormat: Excel date format string
    • NumberFormat: Excel number format string

Formatting options are passed straight to Excel cell formatting. Common examples include dd/mm/yyyy and #,##0.00.

Save to disk with the worksheet model

using TPJ.Excel;
using TPJ.Excel.Models;

var worksheet = new EPPlusWorksheet
{
    Name = "Staff",
    Headers =
    [
        "Staff #",
        "Name",
        "Start Date",
        "Salary"
    ],
    Rows = staff.Select(x => new EPPlusRow
    {
        Data =
        [
            new EPPlusData { Value = x.Id },
            new EPPlusData { Value = x.Name },
            new EPPlusData
            {
                Value = x.StartDate,
                DateFormat = "dd/mm/yyyy"
            },
            new EPPlusData
            {
                Value = x.Salary,
                NumberFormat = "#,##0.00"
            }
        ]
    })
};

EPPlusHelper.Create(worksheet, @"C:\Test\StaffFormatted.xlsx");

Return the file as bytes

using TPJ.Excel;

byte[] excelBytes = EPPlusHelper.Create(worksheet);

Multiple worksheets

using TPJ.Excel;
using TPJ.Excel.Models;

var summarySheet = new EPPlusWorksheet
{
    Name = "Summary",
    Headers = ["Report", "Created"],
    Rows =
    [
        new EPPlusRow
        {
            Data =
            [
                new EPPlusData { Value = "Staff Export" },
                new EPPlusData { Value = DateTime.Today, DateFormat = "dd/mm/yyyy" }
            ]
        }
    ]
};

EPPlusHelper.Create(new[] { summarySheet, worksheet }, @"C:\Test\StaffReport.xlsx");

3. Full control with EPPlus and AddWorksheet

If you need a more custom workbook, use EPPlus directly and let TPJ.Excel help with navigation.

AddWorksheet returns an ExcelWorksheetExtension, which tracks the current row and column for you. It also includes Write(...), WriteNext(...), WriteHeader(...), and WriteRow(...) helpers to cut down repetitive code.

Example

using OfficeOpenXml;
using TPJ.Excel;

using var package = new ExcelPackage();
var ws = package.Workbook.AddWorksheet("Staff");

ws.WriteHeader("Staff #", "Name", "Start Date", "Salary");

foreach (var item in staff)
{
    ws.WriteNext(item.Id)
      .WriteNext(item.Name)
      .WriteNext(item.StartDate, dateFormat: "dd/mm/yyyy")
      .Write(item.Salary, numberFormat: "#,##0.00");

    ws.NextRow();
}

package.SaveAs(new FileInfo(@"C:\Test\StaffAdvanced.xlsx"));

Useful navigation methods

  • CurrentCell() gets the current cell
  • NextColumn() moves one column to the right
  • NextRow() moves to the next row and resets the column back to the first column
  • PreviousColumn() and PreviousRow() let you move backwards
  • Reset() returns to cell A1

Summary

  • Use ExcelDocument for the fastest export
  • Use EPPlusHelper for clean, readable exports with headers and formatting
  • Use full EPPlus support when you need a custom layout or advanced workbook logic

For complete working examples, see TPJ.ExcelTest\Program.cs.

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
10.0.0 46 5/10/2026
1.1.1 223 12/18/2024
1.1.0 973 1/22/2023
1.0.0 431 1/21/2023

V10.0.0 now runs on .NET 10 see github for more details