Sheet Options
.sheet(name, options) takes the same options in the buffered and streaming builders.
| Option | Default | Purpose |
|---|---|---|
freezePane | { rows, columns } that stay visible while scrolling | |
tablesPerRow | 1 | how many tables sit side by side before wrapping to a new row |
tableColumnGap | 1 | empty columns between side-by-side tables |
tableRowGap | 1 | empty rows between stacked tables |
rightToLeft | false | mirror the sheet for right-to-left languages |
protection | true or permissions, see Protection |
Freeze panes
Freeze the rows a reader needs while scrolling, usually the title and header rows, and the identifying columns on wide reports.
import { createExcelSchema, createWorkbook } from "typed-xlsx";
type Account = { account: string; jan: number; feb: number; mar: number };
const schema = createExcelSchema<Account>()
.column("account", { header: "Account", accessor: "account" })
.column("jan", { header: "Jan", accessor: "jan" })
.column("feb", { header: "Feb", accessor: "feb" })
.column("mar", { header: "Mar", accessor: "mar" })
.build();
createWorkbook()
.sheet("Revenue", { freezePane: { rows: 2, columns: 1 } })
.table("revenue", { title: "Monthly revenue", schema, rows: [] });
- 1
A1:D2frozen rows: the title and the header stay on screen - 2
A3:A5frozen column: the account name stays visible when scrolling right
freezePane counts worksheet rows and columns, so with a table title the header is row 2.
Layout of several tables
tablesPerRow, tableColumnGap and tableRowGap decide where each .table() lands. Building Workbooks shows both layouts.
import { createWorkbook } from "typed-xlsx";
createWorkbook().sheet("Dashboard", { tablesPerRow: 3, tableColumnGap: 2, tableRowGap: 2 });
Right-to-left
import { createWorkbook } from "typed-xlsx";
createWorkbook().sheet("تقرير", { rightToLeft: true });
Names and limits
Sheet names are cleaned (\ / * ? : [ ] | become spaces), cut to 31 characters and made unique ignoring case, so Sales and sales become Sales and sales (2). History is reserved by Excel, so a sheet with that name becomes History (2). A hyperlink such as #'Sheet'!A1 must use the final name.
Excel allows 1,048,576 rows and 16,384 columns per sheet. A workbook that would pass either limit throws an error naming the sheet instead of writing a file Excel cannot open.