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';
## Options
### exportFile
<a href="https://github.com/handsontable/handsontable/blob/4397b49c868a478a525cf2f4ec0d6f3d46b0d36e/handsontable/handsontable/src/dataMap/metaManager/metaSchema.js#L2667" target="_blank" rel="noopener noreferrer" class="source-code-link">Source code</a>
_exportFile.exportFile : object_
The `exportFile` option configures the [`ExportFile`](/docs/angular-data-grid/api/export-file/) plugin.
You can set the `exportFile` option to one of the following:
| Setting | Description || ----------- | ------------------------------------------------------------------------------------------ || `undefined` | Use the [`ExportFile`](/docs/angular-data-grid/api/export-file/) plugin with the default configuration || An object | Enable the [`ExportFile`](/docs/angular-data-grid/api/export-file/) plugin and modify the plugin options |
If you set the `exportFile` option to an object, you can configure the following options:
| Option | Type | Default | Description || --------- | -------- | ------- | ----------------------------------------------------------------------------------- || `engines` | `Object` | – | A map of format keys to their engine constructors. Pass `{ xlsx: ExcelJS }` to enable XLSX export via [ExcelJS](https://github.com/exceljs/exceljs). |
Read more:- [Export to Excel](/docs/angular-data-grid/export-to-excel/)- [Plugins: `ExportFile`](/docs/angular-data-grid/api/export-file/)
**Default**: <code>undefined</code>**Since**: 17.1.0**Example**```jsimport ExcelJS from 'exceljs';
// enable XLSX exportexportFile: { engines: { xlsx: ExcelJS },},Methods
disablePlugin
exportFile.disablePlugin()
Disables the plugin functionality for this Handsontable instance.
downloadFile
exportFile.downloadFile(format, options) ⇒ void
Triggers a synchronous file download for text-based export formats (e.g. 'csv').
Calling this method with a binary format (e.g. 'xlsx') throws an error — use
[[ExportFile#downloadFileAsync]] instead.
| Param | Type | Default | Description |
|---|---|---|---|
| format | string | Export format type e.g. 'csv'. | |
| options | object | Export options. | |
| [options.mimeType] | string | optional MIME type. Default depends on format. | |
| [options.fileExtension] | string | optional File extension. Default depends on format. | |
| [options.filename] | string | ”Handsontable [YYYY]-[MM]-[DD]“ | optional File name. |
| [options.encoding] | string | ”utf-8” | optional Character encoding. |
| [options.bom] | boolean | optional Include BOM signature. Default depends on format. | |
| [options.columnDelimiter] | string | ”,“ | optional Column delimiter (CSV only). |
| [options.rowDelimiter] | string | ”\r\n” | optional Row delimiter (CSV only). |
| [options.columnHeaders] | boolean | false | optional Include column headers. |
| [options.rowHeaders] | boolean | false | optional Include row headers. |
| [options.exportHiddenColumns] | boolean | false | optional Include hidden columns. |
| [options.exportHiddenRows] | boolean | false | optional Include hidden rows. |
| [options.range] | Array<number> | [] | optional Cell range: [startRow, startColumn, endRow, endColumn]. |
| [options.sanitizeValues] | boolean RegExp function | false | optional Sanitization (CSV only). |
downloadFileAsync
exportFile.downloadFileAsync(format, options) ⇒ Promise<void>
Triggers an asynchronous file download. Supports all export formats.
For text-based formats (e.g. 'csv'), the download is triggered immediately
and the returned Promise resolves right away.
For binary formats (e.g. 'xlsx'), the export runs asynchronously. When the
dialog plugin is enabled, a progress overlay is shown for the duration of the export.
Since: 17.1.0
| Param | Type | Default | Description |
|---|---|---|---|
| format | string | Export format type e.g. 'csv' or 'xlsx'. | |
| options | object | Export options. | |
| [options.mimeType] | string | optional MIME type. Default depends on format. | |
| [options.fileExtension] | string | optional File extension. Default depends on format. | |
| [options.filename] | string | ”Handsontable [YYYY]-[MM]-[DD]“ | optional File name. |
| [options.encoding] | string | ”utf-8” | optional Character encoding (text formats only). |
| [options.bom] | boolean | optional Include BOM signature (text formats only). | |
| [options.columnDelimiter] | string | ”,“ | optional Column delimiter (CSV only). |
| [options.rowDelimiter] | string | ”\r\n” | optional Row delimiter (CSV only). |
| [options.columnHeaders] | boolean | false | optional Include column headers. |
| [options.rowHeaders] | boolean | false | optional Include row headers. |
| [options.exportHiddenColumns] | boolean | false | optional Include hidden columns. |
| [options.exportHiddenRows] | boolean | false | optional Include hidden rows. |
| [options.range] | Array<number> | [] | optional Cell range: [startRow, startColumn, endRow, endColumn]. |
| [options.sanitizeValues] | boolean RegExp function | false | optional Sanitization (CSV only). |
| [options.exportFormulas] | boolean | false | optional Export cell formulas instead of their computed values (XLSX only). |
| [options.compression] | boolean number | optional Enable DEFLATE compression: true uses level 6; a number 1–9 sets a specific level. Omit or pass a falsy value to use no compression (XLSX only). | |
| [options.conditionalFormatting] | Array<ConditionalFormattingDescriptor> | [] | optional Conditional formatting rules to apply to the exported file (XLSX only). |
| [options.sheets] | Array<SheetOptions> | [] | optional Configuration for multi-sheet export. Each entry defines one worksheet (XLSX only). |
enablePlugin
exportFile.enablePlugin()
Enables the plugin functionality for this Handsontable instance.
exportAsBlob
exportFile.exportAsBlob(format, options) ⇒ Blob
Exports table data as a blob object.
This method is only supported for text-based formats such as CSV.
Calling it with a binary format (e.g. 'xlsx') throws an error — use
[[ExportFile#exportAsBlobAsync]] instead.
| Param | Type | Default | Description |
|---|---|---|---|
| format | string | Export format type e.g. 'csv'. | |
| options | object | Export options. | |
| [options.mimeType] | string | optional MIME type. Default depends on format. | |
| [options.fileExtension] | string | optional File extension. Default depends on format. | |
| [options.filename] | string | ”Handsontable [YYYY]-[MM]-[DD]“ | optional File name. |
| [options.encoding] | string | ”utf-8” | optional Character encoding. |
| [options.bom] | boolean | optional Include BOM signature. Default depends on format (e.g. true for CSV). | |
| [options.columnDelimiter] | string | ”,“ | optional Column delimiter (CSV only). |
| [options.rowDelimiter] | string | ”\r\n” | optional Row delimiter (CSV only). |
| [options.columnHeaders] | boolean | false | optional Include column headers. |
| [options.rowHeaders] | boolean | false | optional Include row headers. |
| [options.exportHiddenColumns] | boolean | false | optional Include hidden columns. |
| [options.exportHiddenRows] | boolean | false | optional Include hidden rows. |
| [options.range] | Array<number> | [] | optional Cell range: [startRow, startColumn, endRow, endColumn]. |
| [options.sanitizeValues] | boolean RegExp function | false | optional Sanitization (CSV only). |
exportAsBlobAsync
exportFile.exportAsBlobAsync(format, options) ⇒ Promise<Blob>
Exports table data as a blob object, asynchronously.
Supports all export formats. For text-based formats (e.g. 'csv'),
the Promise resolves immediately. For binary formats (e.g. 'xlsx'),
the export runs asynchronously.
Since: 17.1.0
| Param | Type | Default | Description |
|---|---|---|---|
| format | string | Export format type e.g. 'csv' or 'xlsx'. | |
| options | object | Export options. | |
| [options.mimeType] | string | optional MIME type. Default depends on format. | |
| [options.fileExtension] | string | optional File extension. Default depends on format. | |
| [options.filename] | string | ”Handsontable [YYYY]-[MM]-[DD]“ | optional File name. |
| [options.encoding] | string | ”utf-8” | optional Character encoding (text formats only). |
| [options.bom] | boolean | optional Include BOM signature (text formats only). | |
| [options.columnDelimiter] | string | ”,“ | optional Column delimiter (CSV only). |
| [options.rowDelimiter] | string | ”\r\n” | optional Row delimiter (CSV only). |
| [options.columnHeaders] | boolean | false | optional Include column headers. |
| [options.rowHeaders] | boolean | false | optional Include row headers. |
| [options.exportHiddenColumns] | boolean | false | optional Include hidden columns. |
| [options.exportHiddenRows] | boolean | false | optional Include hidden rows. |
| [options.range] | Array<number> | [] | optional Cell range: [startRow, startColumn, endRow, endColumn]. |
| [options.sanitizeValues] | boolean RegExp function | false | optional Sanitization (CSV only). |
| [options.exportFormulas] | boolean | false | optional Export cell formulas instead of their computed values (XLSX only). |
| [options.compression] | boolean number | optional Enable DEFLATE compression: true uses level 6; a number 1–9 sets a specific level. Omit or pass a falsy value to use no compression (XLSX only). | |
| [options.conditionalFormatting] | Array<ConditionalFormattingDescriptor> | [] | optional Conditional formatting rules to apply to the exported file (XLSX only). |
| [options.sheets] | Array<SheetOptions> | [] | optional Configuration for multi-sheet export. Each entry defines one worksheet (XLSX only). |
exportAsString
exportFile.exportAsString(format, options) ⇒ string
Exports table data as a string.
This method is only supported for text-based formats such as CSV.
Calling it with a binary format (e.g. 'xlsx') throws an error.
| Param | Type | Default | Description |
|---|---|---|---|
| format | string | Export format type eq. 'csv'. | |
| options | object | Export options. | |
| [options.mimeType] | string | optional MIME type (e.g. 'text/csv' for CSV). Default depends on format. | |
| [options.fileExtension] | string | optional File extension (e.g. 'csv'). Default depends on format. | |
| [options.filename] | string | ”Handsontable [YYYY]-[MM]-[DD]“ | optional File name. Placeholders [YYYY], [MM], [DD] are replaced with the current date. |
| [options.encoding] | string | ”utf-8” | optional Character encoding. |
| [options.bom] | boolean | optional Include BOM signature. Default depends on format (e.g. true for CSV). | |
| [options.columnDelimiter] | string | ”,“ | optional Column delimiter (CSV only). |
| [options.rowDelimiter] | string | ”\r\n” | optional Row delimiter (CSV only). |
| [options.columnHeaders] | boolean | false | optional Include column headers in the exported file. |
| [options.rowHeaders] | boolean | false | optional Include row headers in the exported file. |
| [options.exportHiddenColumns] | boolean string | false | optional Controls how hidden columns are handled. true exports them as normal visible columns. false omits them entirely. 'hide' exports them and marks them as hidden in Excel (XLSX only). |
| [options.exportHiddenRows] | boolean string | false | optional Controls how hidden rows are handled. true exports them as normal visible rows. false omits them entirely. 'hide' exports them and marks them as hidden in Excel (XLSX only). |
| [options.range] | Array<number> | [] | optional Cell range to export: [startRow, startColumn, endRow, endColumn] (visual indexes). |
| [options.sanitizeValues] | boolean RegExp function | false | optional Controls the sanitization of cell values (CSV only). |
isEnabled
exportFile.isEnabled() ⇒ boolean
Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit
hook and if it returns true then the ExportFile#enablePlugin method is called.
supportsExportFormat
exportFile.supportsExportFormat(format) ⇒ boolean
Returns true when the plugin can produce an export in the given format.
For text-based formats such as 'csv', no extra setup is required and the
method always returns true.
For binary formats such as 'xlsx', the method returns true only when the
corresponding engine has been provided in the plugin’s engines map.
| Param | Type | Description |
|---|---|---|
| format | string | Export format — 'csv' or 'xlsx'. |