ExportFile
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 aPromise). Requires the ExcelJS library to be passed as theengineoption 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 — synchronousexportPlugin.exportAsString('csv');exportPlugin.exportAsBlob('csv');exportPlugin.downloadFile('csv', { filename: 'MyFile' });
// XLSX — asynchronousconst blob = await exportPlugin.exportAsBlobAsync('xlsx');await exportPlugin.downloadFileAsync('xlsx', { filename: 'MyFile' });
// CSV with optionsexportPlugin.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 optionsawait exportPlugin.downloadFileAsync('xlsx', { filename: 'MyFile', columnHeaders: true, rowHeaders: true, exportHiddenRows: false, exportHiddenColumns: false, range: [0, 0, 9, 4],});