Rowpine for TanStack Table
Buy a license
DocsAPI reference

Low-level API

The pieces the exporters are built from: reading a table into a sheet, and building files without saving them.

rowpine 1.0.3Generated from the package's type definitions

readTable

function

Read a TanStack table into a sheet: the visible exported columns in screen order, and the rows opts.rows picks.

Signature
readTable(table: TableLike, opts?: ReadOptions) => Sheet

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalReadOptionsWhich rows to read, and an optional rowStyle. Default: every row.

Returns

Sheet

TableLike

interface

The parts of a TanStack table the exporters read.

Properties

NameTypeDescription
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() => RowModelLikeTanStack 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() => RowModelLikeTanStack 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.
stateoptionalobjectv9 React: the selected state.

ColumnLike

interface

The parts of a TanStack column the exporters read.

Properties

NameTypeDescription
idstringTanStack 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.
accessorFnoptionalunknownTanStack sets this on columns with an accessor.
parentoptionalColumnLikeTanStack 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

interface

The parts of a TanStack row the exporters read.

Properties

NameTypeDescription
idstringTanStack row.id.
depthnumberTanStack row.depth. The nesting level of each row when exporting the current page.
originalunknownTanStack row.original. Passed to rowStyle, format and cellStyle.
subRowsRowLike[]TanStack row.subRows. Walked to export groups and tree rows under their parent.
groupingColumnIdoptionalstringTanStack row.groupingColumnId. On a group row, the column that shows the group label.
groupingValueoptionalunknownTanStack row.groupingValue. On a group row, the label text.
getValue(columnId: string) => unknownTanStack 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

type

A table read into plain data by readTable. Every exporter writes from one.

Properties

NameTypeDescription
columnsSheetColumn[]The exported columns in screen order: pinned start columns, the rest, pinned end columns.
rowsSheetRow[]The exported rows, in output order.
freezeColumnsnumberLeading columns pinned left on screen.

SheetColumn

type

One exported column of a Sheet, with its meta.rowpine settings resolved.

Properties

NameTypeDescription
idstringThe TanStack column id.
headerstringHeader text: meta.rowpine.header, else the string header, else the id, after any parent group headers joined with ' / '.
widthnumberWidth 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.
numFmtoptionalstringmeta.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" | SubtotalAggThe column's aggregation when it maps to SUBTOTAL; auto resolves per value.

SheetRow

type

One exported row of a Sheet. Rows are in output order, each parent followed by its descendants.

Properties

NameTypeDescription
kind"group" | "data"group is a TanStack grouped row; data is anything else.
depthnumberNesting depth: 0 for top-level rows.
valuesunknown[]Raw values, aligned with the columns. Group rows hold aggregates.
blankboolean[]Which values to leave blank on screen-shaped output (grouped-by cells of leaf rows).
labelAtoptionalnumberIndex of the column showing a group row's label, and the label.
labeloptionalstringA group row's label: the grouping value as text.
descendantsnumberHow many sheet rows directly follow this one as its descendants.
hasChildrenbooleanTrue when the row has child rows (a group, or a parent in tree data).
originalunknownThe TanStack row's original data.
styleoptionalCellStyleWhat rowStyle returned for this row.

tableToXlsxModel

function

The workbook model for a table. Pure apart from reading the table.

Signature
tableToXlsxModel(
  table: TableLike,
  opts?: XlsxExportOptions,
  notes?: string[],
) => XlsxModel

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalXlsxExportOptionsWhich rows to read, the sheet name and the group row fill.
notesoptionalstring[]Text lines written below the data, after one empty row.

Returns

XlsxModel

sheetToXlsxModel

function

The workbook model for a sheet. Pure: no zip, no license check.

Signature
sheetToXlsxModel(sheet: Sheet, opts?: XlsxExportOptions, notes?: string[]) => XlsxModel

Parameters

NameTypeDescription
sheetSheetA sheet from readTable.
optsoptionalXlsxExportOptionsSheet name and group row fill. rows, fileName and download are not read here.
notesoptionalstring[]Text lines written below the data, after one empty row.

Returns

XlsxModel

buildXlsxParts

function

Build the OOXML package parts for a single-sheet workbook. Returns a map of path -> xml string ready to be zipped by packageXlsx.

Signature
buildXlsxParts(model: XlsxModel) => Record<string, string>

Parameters

NameTypeDescription
modelXlsxModelThe workbook to write.

Returns

Record<string, string>

XlsxModel

type

A single-sheet workbook as data: what buildXlsxParts writes.

Properties

NameTypeDescription
sheetNamestringWorksheet name. Characters Excel forbids in a sheet name become spaces, the name is cut to 31 characters, and an empty result becomes 'Sheet1'.
headerreadonly string[]Header labels (row 1).
rowsreadonly (readonly XlsxCell[])[]Data rows (each an array of cells, column-aligned with header).
widthsoptionalreadonly number[]Per-column widths in pixels (optional).
freezeHeaderoptionalbooleanFreeze the header row.
freezeColumnsoptionalnumberFreeze this many leading columns.
condFormatsoptionalreadonly XlsxCondFormat[]Native column conditional formatting (data bars / color scales).
tableoptionalXlsxTableSpecWrap the data in a native Excel Table.
outlineoptionalreadonly 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.
notesoptionalreadonly string[]Plain text lines written below the data, after one empty row.

XlsxCell

type

One worksheet cell, already resolved by the caller.

Properties

NameTypeDescription
t"n" | "d" | "s" | "b"'n' number, 'd' date, 's' string, 'b' boolean.
valuestring | number | boolean | Date | nullThe 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.
formulaoptionalstringA 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.
numFmtoptionalstringExcel number-format code (for 'n' / 'd').
alignoptional"left" | "center" | "right"Horizontal alignment. 'left' writes no alignment, the same as leaving it out.
filloptionalstringBackground fill hex (e.g. '#fee2e2').
coloroptionalstringFont color hex.
boldoptionalbooleanBold text.
linkoptionalstringHyperlink URL.

sheetToPdfParams

function

The pdfmake document parameters for a sheet. Pure.

Signature
sheetToPdfParams(
  sheet: Sheet,
  opts?: PdfTableExportOptions,
  notes?: string[],
  now?: Date,
) => PdfDocParams

Parameters

NameTypeDescription
sheetSheetA sheet from readTable.
optsoptionalPdfTableExportOptionsPDF options, passed through to the document. rows, fileName and download are not read here.
notesoptionalstring[]Text lines printed below the table in small grey type.
nowoptionalDateThe date in the page footer and the document properties. Default: the current time.

Returns

PdfDocParams