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.
Import #
import { createXlsx, downloadXlsx } from '@exhaustive-ui/core/xlsx';Basic #
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.
| Code | Name | Quantity |
|---|---|---|
| f230fh0g3 | Bamboo Watch | 24 |
| nvklal433 | Black Watch | 61 |
| zz21cz3c1 | Blue Band | 2 |
| 244wgerg2 | Blue T-Shirt | 25 |
Types and Formats #
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.
| Order | Date | Amount | Discount | Paid |
|---|---|---|---|---|
| SO-1001 | Mar 14, 2026 | €1,250.50 | 10% | Yes |
| SO-1002 | Mar 21, 2026 | €89.90 | 0% | No |
| SO-1003 | Apr 2, 2026 | €4,320.00 | 15% | Yes |
Multiple Sheets #
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.
Blob #
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.
Table #
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' } } })" />Security #
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.
API #
Functions of @exhaustive-ui/core/xlsx.
| Name | Parameters | Description |
|---|---|---|
| createXlsx | workbook: XlsxWorkbook options?: XlsxOptions | Returns a promise of the workbook as a Blob, compressed when the platform has CompressionStream. |
| createXlsxSync | workbook: XlsxWorkbook | Returns 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
| Name | Type | Description |
|---|---|---|
| name | string | Name of the tab, cleaned, at most 31 characters and unique. Sheet1, Sheet2... by default. |
| columns | XlsxColumn[] | Columns of the sheet. Without columns, object rows use the keys of the first row. |
| rows | XlsxRow[] | Arrays of values in the order of the columns, or objects read with the key of each column. A value can be an XlsxCell. |
| frozenHeader | boolean | Whether the header row stays visible when scrolling, true by default when there is a header row. |
| autoFilter | boolean | Whether the header row has filter buttons, true by default when there is a header row. |
| boldHeader | boolean | Whether the header cells are bold, true by default. |
| rightToLeft | boolean | Whether the sheet is displayed from right to left. |
XlsxColumn
| Name | Type | Description |
|---|---|---|
| header | string | Text of the header cell. |
| key | string | Property 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. |
| numFmt | string | Excel number format, replacing the default format of the type. |
| width | number | Width in characters, computed from the content when undefined. |
| currency | string | Currency symbol of a currency column, $ by default. |