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';
## 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**
```js
import ExcelJS from 'exceljs';
// enable XLSX export
exportFile: {
engines: { xlsx: ExcelJS },
},

Methods

disablePlugin

Source code

exportFile.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

downloadFile

Source code

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.

ParamTypeDefaultDescription
formatstringExport format type e.g. 'csv'.
optionsobjectExport options.
[options.mimeType]stringoptional MIME type. Default depends on format.
[options.fileExtension]stringoptional 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]booleanoptional 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]booleanfalseoptional Include column headers.
[options.rowHeaders]booleanfalseoptional Include row headers.
[options.exportHiddenColumns]booleanfalseoptional Include hidden columns.
[options.exportHiddenRows]booleanfalseoptional Include hidden rows.
[options.range]Array<number>[]optional Cell range: [startRow, startColumn, endRow, endColumn].
[options.sanitizeValues]boolean
RegExp
function
falseoptional Sanitization (CSV only).

downloadFileAsync

Source code

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

ParamTypeDefaultDescription
formatstringExport format type e.g. 'csv' or 'xlsx'.
optionsobjectExport options.
[options.mimeType]stringoptional MIME type. Default depends on format.
[options.fileExtension]stringoptional 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]booleanoptional 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]booleanfalseoptional Include column headers.
[options.rowHeaders]booleanfalseoptional Include row headers.
[options.exportHiddenColumns]booleanfalseoptional Include hidden columns.
[options.exportHiddenRows]booleanfalseoptional Include hidden rows.
[options.range]Array<number>[]optional Cell range: [startRow, startColumn, endRow, endColumn].
[options.sanitizeValues]boolean
RegExp
function
falseoptional Sanitization (CSV only).
[options.exportFormulas]booleanfalseoptional 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

Source code

exportFile.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

exportAsBlob

Source code

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.

ParamTypeDefaultDescription
formatstringExport format type e.g. 'csv'.
optionsobjectExport options.
[options.mimeType]stringoptional MIME type. Default depends on format.
[options.fileExtension]stringoptional 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]booleanoptional 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]booleanfalseoptional Include column headers.
[options.rowHeaders]booleanfalseoptional Include row headers.
[options.exportHiddenColumns]booleanfalseoptional Include hidden columns.
[options.exportHiddenRows]booleanfalseoptional Include hidden rows.
[options.range]Array<number>[]optional Cell range: [startRow, startColumn, endRow, endColumn].
[options.sanitizeValues]boolean
RegExp
function
falseoptional Sanitization (CSV only).

exportAsBlobAsync

Source code

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

ParamTypeDefaultDescription
formatstringExport format type e.g. 'csv' or 'xlsx'.
optionsobjectExport options.
[options.mimeType]stringoptional MIME type. Default depends on format.
[options.fileExtension]stringoptional 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]booleanoptional 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]booleanfalseoptional Include column headers.
[options.rowHeaders]booleanfalseoptional Include row headers.
[options.exportHiddenColumns]booleanfalseoptional Include hidden columns.
[options.exportHiddenRows]booleanfalseoptional Include hidden rows.
[options.range]Array<number>[]optional Cell range: [startRow, startColumn, endRow, endColumn].
[options.sanitizeValues]boolean
RegExp
function
falseoptional Sanitization (CSV only).
[options.exportFormulas]booleanfalseoptional 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

Source code

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.

ParamTypeDefaultDescription
formatstringExport format type eq. 'csv'.
optionsobjectExport options.
[options.mimeType]stringoptional MIME type (e.g. 'text/csv' for CSV). Default depends on format.
[options.fileExtension]stringoptional 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]booleanoptional 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]booleanfalseoptional Include column headers in the exported file.
[options.rowHeaders]booleanfalseoptional Include row headers in the exported file.
[options.exportHiddenColumns]boolean
string
falseoptional 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
falseoptional 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
falseoptional Controls the sanitization of cell values (CSV only).

isEnabled

Source code

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

Source code

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.

ParamTypeDescription
formatstringExport format — 'csv' or 'xlsx'.