JavaScript Data Grid Export to CSV
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.
Available methods
The plugin exposes the following methods to export data.
downloadFile(format, options)
- allows you to generate a downloadable file, directly in your browser.exportAsBlob(format, options)
- allows you to export a JavaScript Blob object.exportAsString(format, options)
- allows you to export data as a string.
All of them accept the same arguments:
String
format This is required to prepare a predefined settings object. We currently allow for only 'csv'
to be used.
Object
options This is an optional argument. It contains a set of supported options and extends the predefined CSV configuration. For the complete list of options that you can use, see available options.
Available options in the export configuration
Below you can find all supported options:
Boolean
bom Allows you to export data with a BOM signature.
Note that this property will prepend content with the UTF-16BE BOM signature (FE FF). The browser will convert the signature to the UTF-8 value (EF BB BF) automatically.
You can use this property in all of the available methods.
Default value: true
String
columnDelimiter Allows you to define the columns delimiter.
You can use this property in all of the available methods.
Default value: ','
Boolean
columnHeaders When set to true
, includes column headers in the exported data.
You can use this property in all of the available methods.
The columnHeaders
option doesn't support the NestedHeaders
plugin.
Default value: false
Boolean
exportHiddenColumns Allows you to export data from hidden columns.
You can use this property in all of the available methods.
Default value: false
Boolean
exportHiddenRows Allows you to export data from hidden rows.
You can use this property in all of the available methods.
Default value: false
String
fileExtension Allows you to define the file extension.
You can use this property in the downloadFile()
method.
Default value: 'csv'
String
filename Allows you to define the file name.
You can use predefined placeholders, which will be replaced by the date.
You can use this property in the downloadFile()
method.
Default value: 'Handsontable [YYYY]-[MM]-[DD]'
String
mimeType Allows you to define the MIME type.
You can use this property in the downloadFile()
and exportAsBlob()
methods.
Default value: 'text/csv'
Array
range Allows you to define a range of dataset to export. It's represented by an array of numeric, visual indexes [startRow, startColumn, endRow, endColumn]
.
You can use this property in all of the available methods.
Default value: 'text/csv'
String
rowDelimiter Allows you to define rows delimiter.
You can use this property in all of the available methods.
Default value: '\r\n'
Boolean
rowHeaders Allows you to export data with their row header.
You can use this property in all of the available methods.
Default value: false
Related API reference
- Plugins: