InvoiceExportKit.Templates 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package InvoiceExportKit.Templates --version 1.0.0
                    
NuGet\Install-Package InvoiceExportKit.Templates -Version 1.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="InvoiceExportKit.Templates" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="InvoiceExportKit.Templates" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="InvoiceExportKit.Templates" />
                    
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 InvoiceExportKit.Templates --version 1.0.0
                    
#r "nuget: InvoiceExportKit.Templates, 1.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 InvoiceExportKit.Templates@1.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=InvoiceExportKit.Templates&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=InvoiceExportKit.Templates&version=1.0.0
                    
Install as a Cake Tool

InvoiceExportKit

A lightweight, open-source .NET 8 library for exporting professional invoice documents to Excel (.xlsx) using the Open XML SDK. Designed as a reusable, NuGet-friendly toolkit with clean separation of concerns.


Features

  • Export invoices to .xlsx with full Open XML SDK support
  • Seller and buyer information blocks (name, address, tax ID, email, phone)
  • Invoice metadata: number, issue date, due date, currency, notes
  • Line items with code, description, quantity, unit, unit price, discount %, and totals
  • Totals section: subtotal, discount, tax, and final total
  • Visual formatting: merged cells, custom column widths, borders, bold headers, number/date formatting, horizontal alignment
  • Two built-in templates: Simple (clean blue) and Corporate (dark header, row banding)
  • Pluggable template system — implement IInvoiceTemplate and pass it in
  • Validation layer with descriptive error messages
  • Auto-calculation of line totals and invoice totals
  • ASP.NET Core Web API sample with POST /api/invoices/export/excel
  • Console sample generating both templates to an output folder

Project Structure

InvoiceExportKit/
├── src/
│   ├── InvoiceExportKit.Abstractions      # Models, contracts, options (no dependencies)
│   ├── InvoiceExportKit.Core              # Validation + totals calculation (→ Abstractions)
│   ├── InvoiceExportKit.Excel.OpenXml     # Open XML rendering (→ Abstractions, Templates)
│   └── InvoiceExportKit.Templates         # Built-in templates: Simple & Corporate (→ Abstractions)
├── samples/
│   ├── InvoiceExportKit.ConsoleSample     # CLI sample: writes .xlsx files to /output
│   └── InvoiceExportKit.WebApiSample      # ASP.NET Core API sample
└── tests/
    ├── InvoiceExportKit.Core.Tests        # Calculation & validation unit tests
    └── InvoiceExportKit.Excel.OpenXml.Tests # Export integration tests

Dependency Graph

Abstractions  ←  Core
Abstractions  ←  Templates
Abstractions  ←  Excel.OpenXml  ←  Templates

Business logic (Core) has zero dependency on the rendering layer (Excel.OpenXml).


Quick Start

1. Build the invoice model

var invoice = new InvoiceModel
{
    InvoiceNumber = "INV-2024-001",
    IssueDate     = new DateTime(2024, 11, 1),
    DueDate       = new DateTime(2024, 11, 30),
    Currency      = "USD",
    TaxRate       = 21m,
    Notes         = "Payment within 30 days. Thank you for your business.",

    Seller = new ContactModel
    {
        Name    = "Acme Software LLC",
        TaxId   = "US-12-3456789",
        Email   = "billing@acme.com",
        Address = new AddressModel
        {
            Street = "350 Fifth Avenue", City = "New York",
            PostalCode = "NY 10118", Country = "United States"
        }
    },

    Buyer = new ContactModel
    {
        Name    = "Globex Corp.",
        Address = new AddressModel
        {
            Street = "742 Evergreen Terrace", City = "Springfield",
            PostalCode = "62701", Country = "United States"
        }
    },

    Items =
    [
        new InvoiceItemModel
        {
            Code = "LIC-ENT", Description = "Enterprise License (annual)",
            Quantity = 1, Unit = "license", UnitPrice = 9_999.00m
        },
        new InvoiceItemModel
        {
            Code = "SVC-IMPL", Description = "Implementation Services",
            Quantity = 20, Unit = "hrs", UnitPrice = 150.00m, DiscountPercent = 10m
        }
    ]
};

2. Export

var exporter = new ExcelInvoiceExporter();
var service  = new InvoiceExportService(exporter);

byte[] bytes = service.Export(invoice, new ExportOptions
{
    TemplateName      = "Corporate",  // or "Simple"
    RecalculateTotals = true,
    SheetName         = "Invoice"
});

File.WriteAllBytes("invoice.xlsx", bytes);

3. ASP.NET Core DI

builder.Services.AddSingleton<IInvoiceExporter, ExcelInvoiceExporter>();
builder.Services.AddSingleton<IInvoiceValidator, InvoiceValidator>();
builder.Services.AddScoped<InvoiceExportService>();

Then POST /api/invoices/export/excel with the ExportRequest JSON body (see InvoicesController).


Templates

Name Header Row banding Title size
Simple Steel blue None 18 pt
Corporate Dark navy Light blue 20 pt

Custom template

public class BrandedTemplate : IInvoiceTemplate
{
    public string Name => "Branded";
    public TemplateRenderOptions RenderOptions { get; } = new()
    {
        HeaderBackgroundColor = "C00000",
        HeaderFontColor       = "FFFFFF",
        FontName              = "Arial",
        TitleFontSize         = 22,
        ColumnWidths          = new() { [3] = 42 }
    };
}

var exporter = new ExcelInvoiceExporter(customTemplates: [new BrandedTemplate()]);

Running Tests

dotnet test

Running the Console Sample

cd samples/InvoiceExportKit.ConsoleSample
dotnet run
# Output files written to: bin/Debug/net8.0/output/

Running the Web API Sample

cd samples/InvoiceExportKit.WebApiSample
dotnet run
# Swagger UI available at: https://localhost:5001/swagger

Example cURL request:

curl -X POST https://localhost:5001/api/invoices/export/excel \
  -H "Content-Type: application/json" \
  -d '{
    "invoice": {
      "invoiceNumber": "INV-001",
      "issueDate": "2024-11-01",
      "dueDate": "2024-11-30",
      "currency": "USD",
      "taxRate": 20,
      "seller": { "name": "Seller Co", "address": { "street": "1 Main", "city": "NYC", "postalCode": "10001", "country": "US" } },
      "buyer":  { "name": "Buyer Inc", "address": { "street": "2 Main", "city": "LA",  "postalCode": "90001", "country": "US" } },
      "items": [{ "description": "Consulting", "quantity": 5, "unit": "hrs", "unitPrice": 200 }]
    },
    "options": { "templateName": "Corporate" }
  }' \
  --output invoice.xlsx

Roadmap

  • PDF export via a pluggable IPdfInvoiceExporter (QuestPDF / iText)
  • Multiple currency symbol rendering in cells (not just ISO code)
  • Logo / image embedding support for Corporate template
  • Localization support (date formats, decimal separators) via CultureInfo
  • Async export API (ExportAsync) for streaming large workbooks
  • IBAN / payment-details section in the template
  • Additional built-in templates: Minimal, A4Formal
  • NuGet packages published to nuget.org
  • GitHub Actions CI pipeline (build + test)

License

MIT — see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on InvoiceExportKit.Templates:

Package Downloads
InvoiceExportKit.Excel.OpenXml

Lightweight .NET library for exporting professional invoice Excel files using Open XML.

InvoiceExportKit

Meta-package for InvoiceExportKit. Installs all required packages in one step: Abstractions, Core, Templates and Excel.OpenXml.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 155 5/13/2026
1.0.1 123 5/13/2026
1.0.0 117 5/13/2026