Skip to content

Export your grid’s raw data to the CSV format, as a downloadable file, a blob, or a string. Customize your export using Handsontable’s configuration options.

Examples

Mind that CSV exports contain only raw data, and don’t include formulas, styling, or formatting information.

Export to file

Export as a JavaScript Blob object

Open a console in browser developer tools to see the result for the below example.

Export as a string

Open a console in browser developer tools to see the result for the below example.

Prevent CSV Injection attack

“CSV Injection, also known as Formula Injection, occurs when websites embed untrusted input inside CSV files. When a spreadsheet program such as Microsoft Excel or LibreOffice Calc is used to open a CSV, any cells starting with = will be interpreted by the software as a formula.” (from OWASP website)

To prevent this attack, set the sanitizeValues option when exporting your data in CSV format.

Available methods

The plugin exposes the following methods to export data.

Each method takes two parameters. The first, format, is required. The second, options, is an optional object that overrides or extends the default export configuration. The table below lists all supported options for CSV export.

Available options in the export configuration

PropertyType / DefaultDescription
bomBoolean, default truePrepend output with BOM (UTF-8). Browser uses EF BB BF.
colHeadersBoolean, default falseInclude column headers. Does not support the NestedHeaders plugin.
columnDelimiterString, default ','Column delimiter.
exportHiddenColumnsBoolean, default falseInclude hidden columns.
exportHiddenRowsBoolean, default falseInclude hidden rows.
fileExtensionString, default 'csv'File extension. Used by downloadFile().
filenameString, default 'Handsontable [YYYY]-[MM]-[DD]'File name. Placeholders [YYYY], [MM], [DD] are replaced with the current date. Used by downloadFile().
mimeTypeString, default 'text/csv'MIME type. Used by downloadFile() and exportAsBlob().
rangeArray, default []Cell range to export: [startRow, startColumn, endRow, endColumn] (visual indexes).
rowDelimiterString, default '\r\n'Row delimiter.
rowHeadersBoolean, default falseInclude row headers.
sanitizeValuesBoolean | RegExp | Function, default falseValue sanitization. true = OWASP CSV injection rules; RegExp = escape matching values; Function = replace with return value.

Plugins