Skip to main content

CSV and Excel export

Export the complete view, a selected range, or selected columns from the toolbar, menus, or API.

Loading interactive example…
React
<Grid
rowData={rows}
columnDefs={columns}
allowExportAsCSV
allowExportAsExcel
toolbar={{ export: true }}
onGridReady={(api) => {
// api.exportDataAsExcel({ scope: "selection" });
}}
/>

Output fidelity

Excel output is written without runtime dependencies and includes hierarchical headers, cell spans, full-width row merges, pinned panes, typed number/date/ currency values, and application-pinned rows. Aggregate footers become live formulas when an equivalent Excel function exists.

Grouped export supports a tree with outline levels and per-group subtotals, or a flat leaf mode with full group paths. Selection export prunes the group tree to relevant rows.

Use getDataAsCsv() or getDataAsExcel() when the application needs bytes without triggering a browser download—for example, to upload or encrypt a file.

Enable export commands

const options = {
allowExportAsCSV: true,
allowExportAsExcel: true,
toolbar: { export: true },
} satisfies GridOptions;

Export is also available from column and body context menus.

Download CSV or Excel

api.exportDataAsCsv({ fileName: "orders.csv" });
api.exportDataAsExcel({ fileName: "orders.xlsx" });

Export a range or selected columns

api.exportDataAsCsv({ scope: "selection" });

api.exportDataAsExcel({
scope: "selectedColumns",
columnIds: ["orderNo", "customer", "total"],
includeHeaders: true,
});

Grouped export

api.exportDataAsExcel({ groupMode: "tree" }); // group headers + subtotals
api.exportDataAsExcel({ groupMode: "leaves" }); // flat leaves with group paths

CSV and Excel include application-pinned top and bottom rows around the body.

Pivot export

While pivot mode is on, the same commands export the pivot table itself: the generated nested header over one row per group node (every level, expanded or not, indented under the group column), with real numbers in the aggregate cells. Pivot exports are whole-table by design — the range and selected-column scopes are ignored — and the default filename becomes grid-pivot.csv / grid-pivot.xlsx. Turn pivot mode off to export the source rows instead.

Get bytes without downloading

const csv = api.getDataAsCsv({ scope: "all" });
await fetch("/exports/orders.csv", { method: "PUT", body: csv });

const bytes = await api.getDataAsExcel();
const workbook = new Blob([bytes], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});