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
Summary
Load an existing
.xlsxtemplate 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
Usage
Features
{{key}}patterns and replace with valuesWithPropertiesto override document metadata on the filled templateWhy This Matters