Skip to content

Plugin: ExportFile

Description

The ExportFile plugin lets you export table data as a string, blob, or downloadable file.

Supported formats:

  • CSV ('csv') — synchronous, no additional setup required.
  • XLSX ('xlsx') — asynchronous (returns a Promise). Requires the ExcelJS library to be passed as the engine option in the plugin settings.

See the export file demo for examples.

Example

import ExcelJS from 'exceljs';
const container = document.getElementById('example');
const hot = new Handsontable(container, {
data: getData(),
exportFile: {
engines: { xlsx: ExcelJS },
},
});
const exportPlugin = hot.getPlugin('exportFile');
// CSV — synchronous
exportPlugin.exportAsString('csv');
exportPlugin.exportAsBlob('csv');
exportPlugin.downloadFile('csv', { filename: 'MyFile' });
// XLSX — asynchronous
const blob = await exportPlugin.exportAsBlobAsync('xlsx');
await exportPlugin.downloadFileAsync('xlsx', { filename: 'MyFile' });
// CSV with options
exportPlugin.exportAsString('csv', {
exportHiddenRows: true, // default false
exportHiddenColumns: true, // default false
columnHeaders: true, // default false
rowHeaders: true, // default false
columnDelimiter: ';', // default ','
range: [1, 1, 6, 6] // [startRow, startColumn, endRow, endColumn]
});
// XLSX with options
await exportPlugin.downloadFileAsync('xlsx', {
filename: 'MyFile',
columnHeaders: true,
rowHeaders: true,
exportHiddenRows: false,
exportHiddenColumns: false,
range: [0, 0, 9, 4],
});