Low-level API
The pieces the exporters are built from: reading a table into a sheet, and building files without saving them.
readTable
functionRead a TanStack table into a sheet: the visible exported columns in screen
order, and the rows opts.rows picks.
readTable(table: TableLike, opts?: ReadOptions) => SheetParameters
| Name | Type | Description |
|---|---|---|
table | TableLike | A TanStack table (v8 or v9), or pivot.table from createPivot. |
optsoptional | ReadOptions | Which rows to read, and an optional rowStyle. Default: every row. |
Returns
TableLike
interfaceThe parts of a TanStack table the exporters read.
Properties
| Name | Type | Description |
|---|---|---|
getAllLeafColumns | () => ColumnLike[] | TanStack table.getAllLeafColumns(). The exported columns when the table has no visibility or pinning methods. |
getVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack table.getVisibleLeafColumns(). The exported columns, in order, when the table has no pinning methods. |
getLeftVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack v8 table.getLeftVisibleLeafColumns(). Exported first; the Excel export freezes them. |
getRightVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack v8 table.getRightVisibleLeafColumns(). Exported last. |
getStartVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack v9 table.getStartVisibleLeafColumns(). Used in place of the left columns when present. |
getEndVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack v9 table.getEndVisibleLeafColumns(). Used in place of the right columns when present. |
getCenterVisibleLeafColumnsoptional | (() => ColumnLike[]) | TanStack table.getCenterVisibleLeafColumns(). The unpinned columns, exported between the pinned ones. |
getCoreRowModel | () => RowModelLike | TanStack table.getCoreRowModel(). The rows for rows: 'all' when the table has no filtered, grouped or sorted model. |
getFilteredRowModeloptional | (() => RowModelLike) | TanStack table.getFilteredRowModel(). The rows for rows: 'all' when there is no grouped or sorted model. |
getGroupedRowModeloptional | (() => RowModelLike) | TanStack table.getGroupedRowModel(). The rows for rows: 'all' when there is no sorted model. |
getSortedRowModeloptional | (() => RowModelLike) | TanStack table.getSortedRowModel(). The rows for rows: 'all' when present. |
getRowModel | () => RowModelLike | TanStack table.getRowModel(). The rows for rows: 'page'. |
getSelectedRowModeloptional | (() => RowModelLike) | TanStack table.getSelectedRowModel() (row selection feature). The rows for rows: 'selected'; without it nothing is selected. |
getStateoptional | (() => object) | v8 state. |
storeoptional | { readonly state: object; } | v9 state. |
stateoptional | object | v9 React: the selected state. |
ColumnLike
interfaceThe parts of a TanStack column the exporters read.
Properties
| Name | Type | Description |
|---|---|---|
id | string | TanStack column.id. Used as the column key when reading row values. |
columnDef | { header?: unknown; meta?: unknown; aggregationFn?: unknown; accessorFn?: unknown; accessorKey?: unknown; } | TanStack column.columnDef. The exporters read its string header,
meta.rowpine, a string aggregationFn (for Excel SUBTOTAL formulas),
and accessorFn / accessorKey to tell data columns from display columns. |
accessorFnoptional | unknown | TanStack sets this on columns with an accessor. |
parentoptional | ColumnLike | TanStack column.parent. String headers of parent groups are joined to the leaf header with ' / '. |
getSizeoptional | (() => number) | TanStack column.getSize(). The exported width in px when meta.rowpine.width is not set; 150 when neither exists. |
RowLike
interfaceThe parts of a TanStack row the exporters read.
Properties
| Name | Type | Description |
|---|---|---|
id | string | TanStack row.id. |
depth | number | TanStack row.depth. The nesting level of each row when exporting the current page. |
original | unknown | TanStack row.original. Passed to rowStyle, format and cellStyle. |
subRows | RowLike[] | TanStack row.subRows. Walked to export groups and tree rows under their parent. |
groupingColumnIdoptional | string | TanStack row.groupingColumnId. On a group row, the column that shows the group label. |
groupingValueoptional | unknown | TanStack row.groupingValue. On a group row, the label text. |
getValue | (columnId: string) => unknown | TanStack row.getValue(columnId). The raw value written for each exported column. |
getIsGroupedoptional | (() => boolean) | TanStack row.getIsGrouped() (grouping feature). True marks a group row; without the method no row is a group. |
Sheet
typeA table read into plain data by readTable. Every exporter writes from one.
Properties
| Name | Type | Description |
|---|---|---|
columns | SheetColumn[] | The exported columns in screen order: pinned start columns, the rest, pinned end columns. |
rows | SheetRow[] | The exported rows, in output order. |
freezeColumns | number | Leading columns pinned left on screen. |
SheetColumn
typeOne exported column of a Sheet, with its meta.rowpine settings resolved.
Properties
| Name | Type | Description |
|---|---|---|
id | string | The TanStack column id. |
header | string | Header text: meta.rowpine.header, else the string header, else the id, after any parent group headers joined with ' / '. |
width | number | Width in px: meta.rowpine.width, else the column's TanStack size, else 150. |
align | "left" | "center" | "right" | meta.rowpine.align. Undefined writes no alignment to Excel, and the PDF aligns numbers right. |
numFmtoptional | string | meta.rowpine.numFmt: the Excel number format. |
formatoptional | ((value: unknown, row: unknown) => string) | meta.rowpine.format: display text for the PDF. |
cellStyleoptional | ((value: unknown, row: unknown) => CellStyle | undefined) | meta.rowpine.cellStyle: colors for data cells. |
subtotaloptional | "auto" | SubtotalAgg | The column's aggregation when it maps to SUBTOTAL; auto resolves per value. |
SheetRow
typeOne exported row of a Sheet. Rows are in output order, each parent followed by its descendants.
Properties
| Name | Type | Description |
|---|---|---|
kind | "group" | "data" | group is a TanStack grouped row; data is anything else. |
depth | number | Nesting depth: 0 for top-level rows. |
values | unknown[] | Raw values, aligned with the columns. Group rows hold aggregates. |
blank | boolean[] | Which values to leave blank on screen-shaped output (grouped-by cells of leaf rows). |
labelAtoptional | number | Index of the column showing a group row's label, and the label. |
labeloptional | string | A group row's label: the grouping value as text. |
descendants | number | How many sheet rows directly follow this one as its descendants. |
hasChildren | boolean | True when the row has child rows (a group, or a parent in tree data). |
original | unknown | The TanStack row's original data. |
styleoptional | CellStyle | What rowStyle returned for this row. |
tableToXlsxModel
functionThe workbook model for a table. Pure apart from reading the table.
tableToXlsxModel(
table: TableLike,
opts?: XlsxExportOptions,
notes?: string[],
) => XlsxModelParameters
| Name | Type | Description |
|---|---|---|
table | TableLike | A TanStack table (v8 or v9), or pivot.table from createPivot. |
optsoptional | XlsxExportOptions | Which rows to read, the sheet name and the group row fill. |
notesoptional | string[] | Text lines written below the data, after one empty row. |
Returns
sheetToXlsxModel
functionThe workbook model for a sheet. Pure: no zip, no license check.
sheetToXlsxModel(sheet: Sheet, opts?: XlsxExportOptions, notes?: string[]) => XlsxModelParameters
| Name | Type | Description |
|---|---|---|
sheet | Sheet | A sheet from readTable. |
optsoptional | XlsxExportOptions | Sheet name and group row fill. rows, fileName and download are not read here. |
notesoptional | string[] | Text lines written below the data, after one empty row. |
Returns
buildXlsxParts
functionBuild the OOXML package parts for a single-sheet workbook. Returns a map of
path -> xml string ready to be zipped by packageXlsx.
buildXlsxParts(model: XlsxModel) => Record<string, string>Parameters
| Name | Type | Description |
|---|---|---|
model | XlsxModel | The workbook to write. |
Returns
Record<string, string>
XlsxModel
typeA single-sheet workbook as data: what buildXlsxParts writes.
Properties
| Name | Type | Description |
|---|---|---|
sheetName | string | Worksheet name. Characters Excel forbids in a sheet name become spaces, the name is cut to 31 characters, and an empty result becomes 'Sheet1'. |
header | readonly string[] | Header labels (row 1). |
rows | readonly (readonly XlsxCell[])[] | Data rows (each an array of cells, column-aligned with header). |
widthsoptional | readonly number[] | Per-column widths in pixels (optional). |
freezeHeaderoptional | boolean | Freeze the header row. |
freezeColumnsoptional | number | Freeze this many leading columns. |
condFormatsoptional | readonly XlsxCondFormat[] | Native column conditional formatting (data bars / color scales). |
tableoptional | XlsxTableSpec | Wrap the data in a native Excel Table. |
outlineoptional | readonly number[] | Outline level per data row (0 = top level), aligned with rows. Rows
with a level above 0 form groups Excel can collapse; the summary row sits
above its detail rows, as on screen. |
notesoptional | readonly string[] | Plain text lines written below the data, after one empty row. |
XlsxCell
typeOne worksheet cell, already resolved by the caller.
Properties
| Name | Type | Description |
|---|---|---|
t | "n" | "d" | "s" | "b" | 'n' number, 'd' date, 's' string, 'b' boolean. |
value | string | number | boolean | Date | null | The value. Without a formula, null, undefined and '' write an empty cell. A 'd' value that is not a Date is parsed; 'YYYY-MM-DD' is that local day. |
formulaoptional | string | A formula without the leading '=', e.g. SUBTOTAL(9,C3:C9). value is
written as its cached result, so viewers that do not recalculate still
show the number. |
numFmtoptional | string | Excel number-format code (for 'n' / 'd'). |
alignoptional | "left" | "center" | "right" | Horizontal alignment. 'left' writes no alignment, the same as leaving it out. |
filloptional | string | Background fill hex (e.g. '#fee2e2'). |
coloroptional | string | Font color hex. |
boldoptional | boolean | Bold text. |
linkoptional | string | Hyperlink URL. |
sheetToPdfParams
functionThe pdfmake document parameters for a sheet. Pure.
sheetToPdfParams(
sheet: Sheet,
opts?: PdfTableExportOptions,
notes?: string[],
now?: Date,
) => PdfDocParamsParameters
| Name | Type | Description |
|---|---|---|
sheet | Sheet | A sheet from readTable. |
optsoptional | PdfTableExportOptions | PDF options, passed through to the document. rows, fileName and download are not read here. |
notesoptional | string[] | Text lines printed below the table in small grey type. |
nowoptional | Date | The date in the page footer and the document properties. Default: the current time. |
Returns
PdfDocParams