Rowpine for TanStack Table
Buy a license
DocsAPI reference

Export functions

Write a TanStack table to Excel, PDF or CSV, the options each export takes, and the colors from your theme.

rowpine 1.0.3Generated from the package's type definitions

exportXlsx

function

Export the table to an .xlsx file. Returns the file as a Blob. Without a valid license key it still exports, adds the unlicensed notice line below the data, and logs a console warning once per page load.

Signature
exportXlsx(table: TableLike, opts?: XlsxExportOptions) => Promise<Blob>

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalXlsxExportOptionsExport options. Default: every row, saved as 'export.xlsx'.

Returns

Promise<Blob>

exportPdf

function

Export the table to a PDF file. Returns the file as a Blob. Loads pdfmake and its fonts on first use. Without a valid license key it still exports, prints the unlicensed notice line below the table, and logs a console warning once per page load.

Signature
exportPdf(table: TableLike, opts?: PdfTableExportOptions) => Promise<Blob>

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalPdfTableExportOptionsExport options. Default: every row on A4, saved as 'export.pdf'.

Returns

Promise<Blob>

exportCsv

function

Export the table to a CSV file. Returns the file as a Blob. Free: no license check.

Signature
exportCsv(table: TableLike, opts?: CsvExportOptions) => Promise<Blob>

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalCsvExportOptionsExport options. Default: every row, saved as 'export.csv'.

Returns

Promise<Blob>

tableToCsv

function

The table as CSV text: a header line, then one line per data row. Group rows are left out. Lines end with CRLF. No byte order mark and no file.

Signature
tableToCsv(table: TableLike, opts?: CsvExportOptions) => string

Parameters

NameTypeDescription
tableTableLikeA TanStack table (v8 or v9), or pivot.table from createPivot.
optsoptionalCsvExportOptionsWhich rows to write and the field separator. Default: every row, ','.

Returns

string

XlsxExportOptions

type

Options for exportXlsx and the workbook model functions.

Properties

NameTypeDescription
rowsoptionalRowScopeWhich rows to export. Default 'all'.
rowStyleoptional((original: unknown) => CellStyle | undefined)Style a whole row (e.g. bold totals). Called with the row's original data.
fileNameoptionalstringFile name for the download. '.xlsx' is added unless the name ends with it. Default 'export'.
sheetNameoptionalstringWorksheet name. Default 'Sheet1'.
groupFilloptionalstringFill color of group rows. Default '#f4f4f5', the muted gray of a shadcn/ui table.
downloadoptionalbooleanSave the file in the browser. Default true.

PdfTableExportOptions

type

Options for exportPdf: which rows to read, the PDF page and look, and the file.

Properties

NameTypeDescription
rowsoptionalRowScopeWhich rows to export. Default 'all'.
rowStyleoptional((original: unknown) => CellStyle | undefined)Style a whole row (e.g. bold totals). Called with the row's original data.
pageSizeoptionalPdfPageSizePaper size. Default 'A4'.
pageOrientationoptional"portrait" | "landscape"Default: 'landscape' when there are more columns than autoLandscapeThreshold, else 'portrait'.
marginsoptional[number, number, number, number][left, top, right, bottom] in pt. Default [28, 34, 28, 34].
titleoptionalstringDocument title rendered above the table.
subtitleoptionalstringSmaller line under the title.
logooptionalstringLogo as a data URL, rendered top-left above the title.
logoWidthoptionalnumberLogo width in pt (height auto). Default 90.
fontSizeoptionalnumberBase font size in pt. Default 8.
headerColoroptionalstringHeader row fill color. Default: none, as a shadcn/ui table header.
headerTextColoroptionalstringHeader row text color. Default '#18181b'.
zebraoptionalbooleanStripe alternate rows. Default false, as a shadcn/ui table.
zebraColoroptionalstringStripe fill color. Default '#fafafa'.
repeatHeaderoptionalbooleanRepeat the header row on every page. Default true.
showPageNumbersoptionalbooleanShow the "Page X of Y" + date footer. Default true.
columnWidthsoptional"*" | "auto" | (number | "*" | "auto")[]Column widths: '' (fill, default), 'auto', or an explicit array of pt numbers / 'auto' / '' per column.
autoLandscapeThresholdoptionalnumberSwitch to landscape automatically when column count exceeds this (and no explicit orientation was set). Default 8.
groupColoroptionalstringGroup header row fill color. Default '#f4f4f5'.
groupTextColoroptionalstringGroup header row text color. Default '#18181b'.
subtotalColoroptionalstringFill of group rows and their totals. Default '#f4f4f5'.
chartsoptionalreadonly PdfChartImage[]Charts to print with the table, as image data URLs, each with an optional title and caption. Printed at the content width unless width (pt) says otherwise.
chartsPositionoptional"above" | "below"Where the charts go: above the table (default) or below it.
kpisoptionalreadonly PdfKpi[]A strip of headline numbers above the table: a label, the value, and an optional delta line in its own colour ("+4.2%" in green).
kpiColoroptionalstringKPI box fill. Default '#f4f4f5'.
textColoroptionalstringBody text colour. Default black.
borderColoroptionalstringTable line colour. Default '#e4e4e7'.
verticalLinesoptionalbooleanDraw lines between columns, not only between rows and around the table. Default false, as a shadcn/ui table.
fitoptional"auto" | "shrink" | "split" | "none"What to do when the columns do not fit across the page. - 'auto' (default): shrink the table text, down to three quarters of fontSize; past that, split the columns over several pages. - 'shrink': only shrink, down to 4 pt. - 'split': only split. - 'none': leave it to pdfmake, which lets a wide table run off the page.
repeatColumnsoptionalnumberWhen the columns are split over pages, how many leading columns repeat on every page. Default 1.
grandTotaloptionalbooleanDeprecated. Has no effect: exports add no total row. Kept so existing code still compiles.
labelsoptional{ page?: (page: number, pages: number) => string; date?: (now: Date) => string; subtotal?: (group: string) => string; total?: string; }The words the PDF prints itself, for another language or house style: the page footer, the footer date, a group's subtotal label, and the total row's label.
watermarkoptionalstring | { text: string; color?: string; opacity?: number; }Text printed large and faint across every page: "DRAFT", "CONFIDENTIAL".
authoroptionalstringAuthor recorded in the PDF's document properties.
fontoptionalPdfFontA font to print with instead of Roboto, which has no Chinese, Japanese, Korean, Arabic, Hebrew, Thai or Indic characters (they print as empty boxes). Each file is the font's base64 data or a URL pdfmake can fetch. It must cover Latin too: the whole document uses it.
fileNameoptionalstringFile name for the download. '.pdf' is added unless the name ends with it. Default 'export'.
downloadoptionalbooleanSave the file in the browser. Default true.

PdfExportOptions

type

Page setup and look of a PDF export. Sizes are in pt.

Properties

NameTypeDescription
pageSizeoptionalPdfPageSizePaper size. Default 'A4'.
pageOrientationoptional"portrait" | "landscape"Default: 'landscape' when there are more columns than autoLandscapeThreshold, else 'portrait'.
marginsoptional[number, number, number, number][left, top, right, bottom] in pt. Default [28, 34, 28, 34].
titleoptionalstringDocument title rendered above the table.
subtitleoptionalstringSmaller line under the title.
logooptionalstringLogo as a data URL, rendered top-left above the title.
logoWidthoptionalnumberLogo width in pt (height auto). Default 90.
fontSizeoptionalnumberBase font size in pt. Default 8.
headerColoroptionalstringHeader row fill color. Default: none, as a shadcn/ui table header.
headerTextColoroptionalstringHeader row text color. Default '#18181b'.
zebraoptionalbooleanStripe alternate rows. Default false, as a shadcn/ui table.
zebraColoroptionalstringStripe fill color. Default '#fafafa'.
repeatHeaderoptionalbooleanRepeat the header row on every page. Default true.
showPageNumbersoptionalbooleanShow the "Page X of Y" + date footer. Default true.
columnWidthsoptional"*" | "auto" | (number | "*" | "auto")[]Column widths: '' (fill, default), 'auto', or an explicit array of pt numbers / 'auto' / '' per column.
autoLandscapeThresholdoptionalnumberSwitch to landscape automatically when column count exceeds this (and no explicit orientation was set). Default 8.
groupColoroptionalstringGroup header row fill color. Default '#f4f4f5'.
groupTextColoroptionalstringGroup header row text color. Default '#18181b'.
subtotalColoroptionalstringFill of group rows and their totals. Default '#f4f4f5'.
chartsoptionalreadonly PdfChartImage[]Charts to print with the table, as image data URLs, each with an optional title and caption. Printed at the content width unless width (pt) says otherwise.
chartsPositionoptional"above" | "below"Where the charts go: above the table (default) or below it.
kpisoptionalreadonly PdfKpi[]A strip of headline numbers above the table: a label, the value, and an optional delta line in its own colour ("+4.2%" in green).
kpiColoroptionalstringKPI box fill. Default '#f4f4f5'.
textColoroptionalstringBody text colour. Default black.
borderColoroptionalstringTable line colour. Default '#e4e4e7'.
verticalLinesoptionalbooleanDraw lines between columns, not only between rows and around the table. Default false, as a shadcn/ui table.
fitoptional"auto" | "shrink" | "split" | "none"What to do when the columns do not fit across the page. - 'auto' (default): shrink the table text, down to three quarters of fontSize; past that, split the columns over several pages. - 'shrink': only shrink, down to 4 pt. - 'split': only split. - 'none': leave it to pdfmake, which lets a wide table run off the page.
repeatColumnsoptionalnumberWhen the columns are split over pages, how many leading columns repeat on every page. Default 1.
grandTotaloptionalbooleanDeprecated. Has no effect: exports add no total row. Kept so existing code still compiles.
labelsoptional{ page?: (page: number, pages: number) => string; date?: (now: Date) => string; subtotal?: (group: string) => string; total?: string; }The words the PDF prints itself, for another language or house style: the page footer, the footer date, a group's subtotal label, and the total row's label.
watermarkoptionalstring | { text: string; color?: string; opacity?: number; }Text printed large and faint across every page: "DRAFT", "CONFIDENTIAL".
authoroptionalstringAuthor recorded in the PDF's document properties.
fontoptionalPdfFontA font to print with instead of Roboto, which has no Chinese, Japanese, Korean, Arabic, Hebrew, Thai or Indic characters (they print as empty boxes). Each file is the font's base64 data or a URL pdfmake can fetch. It must cover Latin too: the whole document uses it.

CsvExportOptions

type

Options for exportCsv and tableToCsv.

Properties

NameTypeDescription
rowsoptionalRowScopeWhich rows to export. Default 'all'.
rowStyleoptional((original: unknown) => CellStyle | undefined)Style a whole row (e.g. bold totals). Called with the row's original data.
fileNameoptionalstringFile name for the download. '.csv' is added unless the name ends with it. Default 'export'.
delimiteroptionalstringField separator. Default ','.
bomoptionalbooleanStart the file with a UTF-8 byte order mark so Excel reads accents. Default true.
downloadoptionalbooleanSave the file in the browser. Default true.

RowScope

type

Which rows to export.

Type
type RowScope = 'all'
  | 'page'
  | 'selected'

PdfPageSize

type

Paper sizes the PDF export supports.

Type
type PdfPageSize = 'A4'
  | 'A3'
  | 'A5'
  | 'LETTER'
  | 'LEGAL'

PdfFont

type

A TrueType / OpenType font for the PDF. Missing styles fall back to normal.

Properties

NameTypeDescription
namestringName the font is registered under in pdfmake. The whole document is set in it.
normalstringRegular style: base64 font data, or a URL (http:, https:, blob:, data:, or a path starting with /, ./ or ../).
boldoptionalstringBold style, base64 or a URL. Default: normal.
italicsoptionalstringItalic style, base64 or a URL. Default: normal.
bolditalicsoptionalstringBold italic style, base64 or a URL. Default: bold, else normal.

saveBlob

function

Save a Blob as a file in the browser. Does nothing outside one.

Signature
saveBlob(blob: Blob, fileName: string) => void

Parameters

NameTypeDescription
blobBlobThe file contents.
fileNamestringName the browser saves the file under, used as given.

Returns

void

exportThemeFromPage

function

Read the shadcn/ui theme colors (--background, --foreground, --muted, --border) from the page and return them as export colors. Returns no colors outside a browser, when a variable is missing, or for a dark theme. ExportMenu does this for you; call it when you export from your own buttons.

Signature
exportThemeFromPage(element?: Element) => ExportTheme

Parameters

NameTypeDescription
elementoptionalElementWhere to read the variables. Default: the document's root element.

Returns

ExportTheme

exportThemeFrom

function

The export colors for a set of theme colors. Pure. A dark theme returns no colors: files print on white, so the light defaults fit better.

Signature
exportThemeFrom(colors: ThemeColors | null) => ExportTheme

Parameters

NameTypeDescription
colorsThemeColors | nullThe page's background, foreground, muted and border colors, as hex.

Returns

ExportTheme

ExportTheme

type

Colors for exportPdf and exportXlsx, read from the page. Spread them into the options.

Properties

NameTypeDescription
pdfPick<PdfExportOptions, "headerTextColor" | "textColor" | "groupColor" | "groupTextColor" | "subtotalColor" | "kpiColor" | "borderColor">PDF colors: header and body text, group rows, lines and headline-number boxes.
xlsx{ groupFill?: string; }Excel colors: the group row fill.

ThemeColors

type

The theme colors this reads, as hex.

Properties

NameTypeDescription
backgroundstring
foregroundstring
mutedstring
borderstring

luminance

function

Relative luminance of a #rrggbb color, 0 (black) to 1 (white).

Signature
luminance(hex: string) => number

Parameters

NameTypeDescription
hexstring

Returns

number