Skip to content

FromTemplate — fill existing Excel templates with data #5

@khatabwedaa

Description

@khatabwedaa

Summary

Load an existing .xlsx template file and fill it with data instead of building a spreadsheet from scratch. This is a critical feature for enterprise and finance use cases where teams provide pre-formatted templates with logos, formulas, and complex layouts.

Planned Concern

export interface FromTemplate {
  templatePath(): string; // path to .xlsx template file
  bindings(): Record<string, any>; // placeholder → value mapping
}

Usage

class InvoiceExport implements FromTemplate {
  constructor(private readonly invoice: Invoice) {}

  templatePath() {
    return './templates/invoice.xlsx';
  }

  bindings() {
    return {
      '{{company}}': this.invoice.company,
      '{{date}}': this.invoice.date,
      '{{total}}': this.invoice.total,
    };
  }
}

Features

  • Placeholder replacement — scan cells for {{key}} patterns and replace with values
  • Table region filling — define a named range or start cell for repeating row data
  • Preserve formatting — all original styles, formulas, images, and merged cells remain intact
  • Combine with other concerns — e.g. WithProperties to override document metadata on the filled template

Why This Matters

  • Finance/accounting teams maintain their own Excel templates — they don't want devs recreating layouts in code
  • Invoices, contracts, compliance reports all follow strict formatting that's easier to maintain in Excel than in code
  • No other NestJS package offers this cleanly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestv0.1.xPatch releases for v0.1

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions