v22.18.0 release notes

Excel Export

The xlsx utility creates real Excel workbooks in the browser, with typed cells, dates, number formats, a frozen and filterable header and several sheets. It has no dependency and a Table exports its data with it.

View as .md
import { createXlsx, downloadXlsx } from '@exhaustive-ui/core/xlsx';

downloadXlsx(workbook, filename) builds an Excel workbook in the browser and saves it. A workbook has sheets; a sheet has columns, each with a header and the key of the row objects it displays, and rows. The header row is bold, stays visible when scrolling and has filter buttons, and the columns are as wide as their content. The utility is a separate entry point with no dependency: it adds nothing to an application that does not import it.

CodeNameQuantity
f230fh0g3Bamboo Watch24
nvklal433Black Watch61
zz21cz3c1Blue Band2
244wgerg2Blue T-Shirt25

The type of a column decides how its values are written: string, number, currency, percent, date, datetime or boolean. Without a type, numbers, booleans and Date objects keep their type and the rest is text. Dates become real Excel dates, that sort and filter as dates, from their local date and time; a date column also reads timestamps and ISO strings such as 2026-03-14. A value that does not convert, such as "n/a" in a number column, is written as text.

Each type has a default number format: the short date of the reader's locale, two decimals for percents and currencies, whose symbol is set by currency. numFmt replaces it with any Excel format code, such as #,##0, 0.0% or dd/mm/yyyy hh:mm, and width sets the width of a column in characters. A cell can also be an object, { value: 1200, type: 'currency', bold: true }, for a cell with its own type, format or bold font, such as a total.

OrderDateAmountDiscountPaid
SO-1001Mar 14, 2026€1,250.5010%Yes
SO-1002Mar 21, 2026€89.900%No
SO-1003Apr 2, 2026€4,320.0015%Yes

A workbook has as many sheets as needed, in the order of the tabs; the first one is active. Their names lose the characters Excel forbids, \ / ? * [ ] :, are cut at 31 characters and made unique, and a sheet without a name is called Sheet1, Sheet2... Without columns, object rows use the keys of the first row as headers and array rows are written as they are, with no header row.

frozenHeader and autoFilter, true by default when the sheet has a header row, keep the header visible and add the filter buttons; boldHeader can turn the bold header off and rightToLeft displays the sheet from right to left.

createXlsx(workbook) returns a promise of the file as a Blob, to upload it, attach it to an e-mail or store it instead of downloading it. The file is compressed with the CompressionStream of the browser, and stored without compression where it does not exist; { compression: 'store' } skips the compression. createXlsxSync(workbook) creates the uncompressed file synchronously. Both work on the server too, for an export endpoint.

p-table has an exportExcel(options) method built on this utility: it exports the visible and exportable columns, with the filters, the sort order and exportFunction applied, to a file named after exportFilename. See Table, Export to Excel.

<p-button label="Export to Excel" (onClick)="dt.exportExcel({ sheetName: 'Products', columns: { price: { type: 'currency' } } })" />

The workbook never contains a formula. A text that starts like one, with =, +, -, @, a tab or a carriage return, is written as text and marked as such, like the leading apostrophe of Excel: data typed by users, such as =HYPERLINK(...), is displayed and never run, even when the cell is edited.

The text is escaped for XML and loses the control characters XML cannot hold; a text longer than the 32,767 characters of a cell is cut. Every part of the file is generated in the browser: no data is sent anywhere and no script or macro is included.

Functions of @exhaustive-ui/core/xlsx.

NameParametersDescription
createXlsx workbook: XlsxWorkbook
options?: XlsxOptions
Returns a promise of the workbook as a Blob, compressed when the platform has CompressionStream.
createXlsxSyncworkbook: XlsxWorkbookReturns the uncompressed workbook as a Blob.
downloadXlsx workbook: XlsxWorkbook
filename = 'download'
options?: XlsxOptions
Creates the workbook and saves it, adding .xlsx to the name when missing. Does nothing outside the browser.

XlsxSheet

NameTypeDescription
namestringName of the tab, cleaned, at most 31 characters and unique. Sheet1, Sheet2... by default.
columnsXlsxColumn[]Columns of the sheet. Without columns, object rows use the keys of the first row.
rowsXlsxRow[]Arrays of values in the order of the columns, or objects read with the key of each column. A value can be an XlsxCell.
frozenHeaderbooleanWhether the header row stays visible when scrolling, true by default when there is a header row.
autoFilterbooleanWhether the header row has filter buttons, true by default when there is a header row.
boldHeaderbooleanWhether the header cells are bold, true by default.
rightToLeftbooleanWhether the sheet is displayed from right to left.

XlsxColumn

NameTypeDescription
headerstringText of the header cell.
keystringProperty of the row objects, a dot path such as customer.name is allowed.
type'string' | 'number' | 'currency' | 'percent' | 'date' | 'datetime' | 'boolean'Type of the cells, inferred from each value when undefined.
numFmtstringExcel number format, replacing the default format of the type.
widthnumberWidth in characters, computed from the content when undefined.
currencystringCurrency symbol of a currency column, $ by default.