Skip to content

Excel Export

RevoGrid Pro exports grid data to .xlsx workbooks through ExportExcelPlugin. The same plugin also keeps the historical CSV drag-and-drop import path, so existing integrations can keep using the ExportExcelPlugin, grid.exportExcel, and export-excel event names.

Source code
src/components/export-excel/ExportExcel.ts
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import { currentTheme, useRandomData } from '../composables/useRandomData';
import './export-excel.scss';
import {
EXCEL_DEMO_ROW_COUNT,
applyExcelDemoGridSettings,
createDefaultExcelDemoExportOptions,
createDefaultExcelDemoGridOptions,
createExcelDemoCellMerge,
createExcelDemoColumnTypes,
createExcelDemoColumns,
createExcelDemoExportConfig,
createExcelDemoPinnedBottomSource,
createExcelDemoPinnedTopSource,
createExcelDemoRows,
type ExcelDemoExportOptions,
type ExcelDemoGridOptions,
} from './export-excel-demo-options';
import {
EXCEL_DEMO_EXPORT_EVENT,
EXCEL_DEMO_OPTIONS_CHANGE_EVENT,
createExcelDemoToolbar,
type ExcelDemoExportEvent,
type ExcelDemoOptionsChangeEvent,
} from './export-excel-demo-toolbar';
const { createRandomData } = useRandomData();
const { isDark } = currentTheme();
import {
ColumnStretchPlugin,
CellMergePlugin,
ExportExcelPlugin,
FormulaPlugin,
RowOddPlugin,
} from '@revolist/revogrid-pro';
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) {
return;
}
const container = document.createElement('div');
container.className = `export-excel-demo grow ${gridOptionsClass(isDark())}`;
let exportOptions = createDefaultExcelDemoExportOptions();
let gridOptions = createDefaultExcelDemoGridOptions(isDark());
const mergeRenderedGridOptions = (options: {
exportOptions: ExcelDemoExportOptions;
gridOptions: ExcelDemoGridOptions;
}) => ({
...options.gridOptions,
...options.exportOptions,
});
const toolbar = createExcelDemoToolbar({ exportOptions, gridOptions });
const grid = document.createElement('revo-grid');
grid.className = 'export-excel-grid cell-border';
grid.columns = createExcelDemoColumns(gridOptions);
grid.columnTypes = createExcelDemoColumnTypes();
grid.cellMerge = createExcelDemoCellMerge(gridOptions);
grid.pinnedTopSource = createExcelDemoPinnedTopSource(gridOptions);
grid.pinnedBottomSource = createExcelDemoPinnedBottomSource(gridOptions);
grid.stretch = 'all';
// Define plugin
grid.plugins = [
ExportExcelPlugin,
FormulaPlugin,
RowOddPlugin,
ColumnStretchPlugin,
CellMergePlugin,
];
toolbar.addEventListener(EXCEL_DEMO_OPTIONS_CHANGE_EVENT, (event) => {
({ exportOptions, gridOptions } = (
event as ExcelDemoOptionsChangeEvent
).detail);
container.classList.toggle('is-dark', gridOptions.theme === 'darkMaterial');
applyExcelDemoGridSettings(
grid,
mergeRenderedGridOptions({ exportOptions, gridOptions }),
);
});
toolbar.addEventListener(EXCEL_DEMO_EXPORT_EVENT, async (event) => {
({ exportOptions, gridOptions } = (event as ExcelDemoExportEvent).detail);
toolbar.exporting = true;
try {
const plugins = await grid.getPlugins();
const plugin = plugins.find(
(p) => p instanceof ExportExcelPlugin,
) as ExportExcelPlugin;
await plugin?.export(createExcelDemoExportConfig(exportOptions));
} finally {
toolbar.exporting = false;
}
// Or dispatch the public event with the same provider options.
// dispatch(grid, 'export-excel', createExcelDemoExportConfig(exportOptions));
});
grid.theme = gridOptions.theme;
grid.hideAttribution = true;
applyExcelDemoGridSettings(
grid,
mergeRenderedGridOptions({ exportOptions, gridOptions }),
);
container.append(toolbar, grid);
parent.appendChild(container);
grid.source = createExcelDemoRows(createRandomData(EXCEL_DEMO_ROW_COUNT));
return () => container.remove();
}
function gridOptionsClass(isDarkTheme: boolean) {
return isDarkTheme ? 'is-dark' : '';
}

Attach ExportExcelPlugin with your grid plugins:

import { ExportExcelPlugin } from '@revolist/revogrid-pro';
grid.plugins = [ExportExcelPlugin];

Trigger export through the event API:

grid.dispatchEvent(
new CustomEvent('export-excel', {
detail: {
workbookName: 'orders.xlsx',
sheetName: 'Orders',
},
}),
);
  • The bundled provider is write-excel-file and exports .xlsx files only.
  • Extensionless workbookName values receive .xlsx.
  • sheetName is normalized for Excel worksheet rules.
  • Export reads grid data stores, not rendered DOM rows, so virtualized offscreen rows are included.
  • Body export follows the store’s visible row projection, preserving current sort and filter order and the expanded/collapsed grouping view.
  • Row order is pinned top rows, body rows, then pinned bottom rows.
  • Columns follow providers.column.getColumns('all').
  • Grid-derived widths and freeze panes are inferred by default from column sizes, colPinStart columns, and pinned-top rows.

When DataGridFormattingPlugin and ExportExcelPlugin are active together, Format Cells settings are transferred automatically to the workbook. This is also the normal setup when DataGridContextMenuPlugin supplies Format Cells:

import {
DataGridContextMenuPlugin,
ExportExcelPlugin,
} from '@revolist/revogrid-pro';
grid.plugins = [DataGridContextMenuPlugin, ExportExcelPlugin];

The export keeps raw numeric and date values as workbook values and attaches native Excel number formats for Number, Currency, Accounting, Percentage, Scientific, Date, Time, Date & time, and Plain text presets. Excel can therefore continue to calculate, sort, and edit those cells. Font family and size, emphasis, text and fill colors, alignment, wrapping, and borders are mapped to workbook cell styles.

Row grouping is exported from the visible provider projection. Group records become merged, indented group-heading rows, while expanded descendants retain their displayed order and descendants hidden by a collapsed group are omitted. context.exportMetadata.rowGrouping also exposes each exported group row’s worksheet row, depth, label, and expanded state to custom providers.

  • Export Providers explains provider precedence, default .xlsx limits, providerOptions, deriveGridOptions, optional ExcelJS and SheetJS adapters, workbook-module adapters, and custom providers.
  • Cell Formatting explains automatic Format Cells transfer, column.excelExport, formula/date/numeral/select helpers, grouped rows and headers, cell merge export support, and the provider context matrix.
  • CSV Import explains CSV-only drag/drop import, allowDrag, allowedExtensions, skipColumnGeneration, events, and plugin import helpers.
  • Migrations explains the SheetJS removal, CSV-only default import, app-owned XLSX import, and provider migration paths as a breaking change from 2.0.8.