# Angular Excel Export (xlsx)

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.

## 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.

```typescript
import { Component } from '@angular/core';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { TableModule } from '@exhaustive-ui/core/table';
import { downloadXlsx, XlsxColumn } from '@exhaustive-ui/core/xlsx';
import { download } from '@exhaustive-ui/icons/round';

@Component({
    template: `
        <div class="card flex flex-col gap-4">
            <p-table [value]="products" [tableStyle]="{ 'min-width': '30rem' }">
                <ng-template #header>
                    <tr>
                        <th>Code</th>
                        <th>Name</th>
                        <th>Quantity</th>
                    </tr>
                </ng-template>
                <ng-template #body let-product>
                    <tr>
                        <td>{{ product.code }}</td>
                        <td>{{ product.name }}</td>
                        <td>{{ product.quantity }}</td>
                    </tr>
                </ng-template>
            </p-table>
            <div>
                <p-button label="Download products.xlsx" [icon]="download" (onClick)="save()" />
            </div>
        </div>
    `,
    standalone: true,
    imports: [TableModule, ButtonModule]
})
export class XlsxBasicDemo {
    download = download;

    products = [
        { code: 'f230fh0g3', name: 'Bamboo Watch', quantity: 24 },
        { code: 'nvklal433', name: 'Black Watch', quantity: 61 },
        { code: 'zz21cz3c1', name: 'Blue Band', quantity: 2 },
        { code: '244wgerg2', name: 'Blue T-Shirt', quantity: 25 }
    ];

    columns: XlsxColumn[] = [
        { header: 'Code', key: 'code' },
        { header: 'Name', key: 'name' },
        { header: 'Quantity', key: 'quantity' }
    ];

    save() {
        downloadXlsx({ sheets: [{ name: 'Products', columns: this.columns, rows: this.products }] }, 'products');
    }
}
```

## 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.

```typescript
import { CurrencyPipe, DatePipe, PercentPipe } from '@angular/common';
import { Component } from '@angular/core';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { TableModule } from '@exhaustive-ui/core/table';
import { downloadXlsx, XlsxColumn } from '@exhaustive-ui/core/xlsx';
import { download } from '@exhaustive-ui/icons/round';

@Component({
    template: `
        <div class="card flex flex-col gap-4">
            <p-table [value]="orders" [tableStyle]="{ 'min-width': '40rem' }">
                <ng-template #header>
                    <tr>
                        <th>Order</th>
                        <th>Date</th>
                        <th>Amount</th>
                        <th>Discount</th>
                        <th>Paid</th>
                    </tr>
                </ng-template>
                <ng-template #body let-order>
                    <tr>
                        <td>{{ order.id }}</td>
                        <td>{{ order.date | date: 'mediumDate' }}</td>
                        <td>{{ order.amount | currency: 'EUR' }}</td>
                        <td>{{ order.discount | percent }}</td>
                        <td>{{ order.paid ? 'Yes' : 'No' }}</td>
                    </tr>
                </ng-template>
            </p-table>
            <div>
                <p-button label="Download orders.xlsx" [icon]="download" (onClick)="save()" />
            </div>
        </div>
    `,
    standalone: true,
    imports: [TableModule, ButtonModule, CurrencyPipe, DatePipe, PercentPipe]
})
export class XlsxTypesDemo {
    download = download;

    orders = [
        { id: 'SO-1001', date: new Date(2026, 2, 14), amount: 1250.5, discount: 0.1, paid: true },
        { id: 'SO-1002', date: new Date(2026, 2, 21), amount: 89.9, discount: 0, paid: false },
        { id: 'SO-1003', date: new Date(2026, 3, 2), amount: 4320, discount: 0.15, paid: true }
    ];

    columns: XlsxColumn[] = [
        { header: 'Order', key: 'id', type: 'string' },
        { header: 'Date', key: 'date', type: 'date', numFmt: 'dd mmm yyyy' },
        { header: 'Amount', key: 'amount', type: 'currency', currency: '€' },
        { header: 'Discount', key: 'discount', type: 'percent', numFmt: '0%' },
        { header: 'Paid', key: 'paid', type: 'boolean' }
    ];

    save() {
        const total = this.orders.reduce((sum, order) => sum + order.amount, 0);

        downloadXlsx(
            {
                sheets: [
                    {
                        name: 'Orders',
                        columns: this.columns,
                        rows: [...this.orders, { id: { value: 'Total', bold: true }, amount: { value: total, bold: true } }]
                    }
                ]
            },
            'orders'
        );
    }
}
```

## 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.

```typescript
import { Component } from '@angular/core';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { downloadXlsx, XlsxWorkbook } from '@exhaustive-ui/core/xlsx';
import { download } from '@exhaustive-ui/icons/round';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-button label="Download report.xlsx" [icon]="download" (onClick)="save()" />
        </div>
    `,
    standalone: true,
    imports: [ButtonModule]
})
export class XlsxMultiplesheetsDemo {
    download = download;

    save() {
        const workbook: XlsxWorkbook = {
            sheets: [
                {
                    name: 'Customers',
                    rows: [
                        { name: 'James Butt', country: 'Algeria', company: 'Benton', balance: 70663 },
                        { name: 'Josephine Darakjy', country: 'Egypt', company: 'Chanay', balance: 82429 },
                        { name: 'Art Venere', country: 'Panama', company: 'Chemel', balance: 28334 }
                    ]
                },
                {
                    name: 'Sales: Q1/Q2',
                    columns: [
                        { header: 'Month', type: 'string' },
                        { header: 'Revenue', type: 'currency' },
                        { header: 'Growth', type: 'percent' }
                    ],
                    rows: [
                        ['January', 12500, 0.04],
                        ['February', 13900, 0.112],
                        ['March', 12100, -0.129],
                        [
                            { value: 'Total', bold: true },
                            { value: 38500, bold: true }
                        ]
                    ]
                },
                {
                    name: 'Notes',
                    rows: [['Generated in the browser with @exhaustive-ui/core/xlsx'], ['No header row: no frozen row and no filter buttons']]
                }
            ]
        };

        downloadXlsx(workbook, 'report');
    }
}
```

## 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.

```typescript
import { Component, signal } from '@angular/core';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { createXlsx } from '@exhaustive-ui/core/xlsx';

@Component({
    template: `
        <div class="card flex flex-col items-center gap-4">
            <p-button label="Create 1,000 rows" (onClick)="create()" />
            <p aria-live="polite" class="m-0">{{ result() }}</p>
        </div>
    `,
    standalone: true,
    imports: [ButtonModule]
})
export class XlsxBlobDemo {
    result = signal('');

    async create() {
        const rows = Array.from({ length: 1000 }, (_, index) => ({ id: index + 1, product: `Product ${index + 1}`, price: Math.round(Math.random() * 10000) / 100, date: new Date(2026, 0, 1 + index) }));
        const blob = await createXlsx({ sheets: [{ name: 'Products', rows }] });

        // Upload it, for example: const body = new FormData(); body.append('file', blob, 'products.xlsx');
        this.result.set(`products.xlsx, ${(blob.size / 1024).toFixed(1)} KB`);
    }
}
```

## 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 .

## 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 .

```typescript
import { Component } from '@angular/core';

@Component({
    template: `
        <div class="doc-tablewrapper" tabindex="0">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Parameters</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>createXlsx</td>
                        <td>
                            workbook: XlsxWorkbook<br />
                            options?: XlsxOptions
                        </td>
                        <td>Returns a promise of the workbook as a Blob, compressed when the platform has CompressionStream.</td>
                    </tr>
                    <tr>
                        <td>createXlsxSync</td>
                        <td>workbook: XlsxWorkbook</td>
                        <td>Returns the uncompressed workbook as a Blob.</td>
                    </tr>
                    <tr>
                        <td>downloadXlsx</td>
                        <td>
                            workbook: XlsxWorkbook<br />
                            filename = 'download'<br />
                            options?: XlsxOptions
                        </td>
                        <td>Creates the workbook and saves it, adding .xlsx to the name when missing. Does nothing outside the browser.</td>
                    </tr>
                </tbody>
            </table>
        </div>
        <h3>XlsxSheet</h3>
        <div class="doc-tablewrapper" tabindex="0">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>name</td>
                        <td>string</td>
                        <td>Name of the tab, cleaned, at most 31 characters and unique. Sheet1, Sheet2... by default.</td>
                    </tr>
                    <tr>
                        <td>columns</td>
                        <td>XlsxColumn[]</td>
                        <td>Columns of the sheet. Without columns, object rows use the keys of the first row.</td>
                    </tr>
                    <tr>
                        <td>rows</td>
                        <td>XlsxRow[]</td>
                        <td>Arrays of values in the order of the columns, or objects read with the key of each column. A value can be an XlsxCell.</td>
                    </tr>
                    <tr>
                        <td>frozenHeader</td>
                        <td>boolean</td>
                        <td>Whether the header row stays visible when scrolling, true by default when there is a header row.</td>
                    </tr>
                    <tr>
                        <td>autoFilter</td>
                        <td>boolean</td>
                        <td>Whether the header row has filter buttons, true by default when there is a header row.</td>
                    </tr>
                    <tr>
                        <td>boldHeader</td>
                        <td>boolean</td>
                        <td>Whether the header cells are bold, true by default.</td>
                    </tr>
                    <tr>
                        <td>rightToLeft</td>
                        <td>boolean</td>
                        <td>Whether the sheet is displayed from right to left.</td>
                    </tr>
                </tbody>
            </table>
        </div>
        <h3>XlsxColumn</h3>
        <div class="doc-tablewrapper" tabindex="0">
            <table class="doc-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>header</td>
                        <td>string</td>
                        <td>Text of the header cell.</td>
                    </tr>
                    <tr>
                        <td>key</td>
                        <td>string</td>
                        <td>Property of the row objects, a dot path such as customer.name is allowed.</td>
                    </tr>
                    <tr>
                        <td>type</td>
                        <td>'string' | 'number' | 'currency' | 'percent' | 'date' | 'datetime' | 'boolean'</td>
                        <td>Type of the cells, inferred from each value when undefined.</td>
                    </tr>
                    <tr>
                        <td>numFmt</td>
                        <td>string</td>
                        <td>Excel number format, replacing the default format of the type.</td>
                    </tr>
                    <tr>
                        <td>width</td>
                        <td>number</td>
                        <td>Width in characters, computed from the content when undefined.</td>
                    </tr>
                    <tr>
                        <td>currency</td>
                        <td>string</td>
                        <td>Currency symbol of a currency column, $ by default.</td>
                    </tr>
                </tbody>
            </table>
        </div>
    `,
    standalone: true,
    imports: []
})
export class XlsxApiDemo {
}
```

