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.
Open a console in browser developer tools to see the result for the below example.
import{ useRef, useEffect }from'react';import{ HotTable }from'@handsontable/react';import{ registerAllModules }from'handsontable/registry';import'handsontable/dist/handsontable.full.min.css';// register Handsontable's modulesregisterAllModules();exportconstExampleComponent=()=>{const hotRef =useRef(null);let buttonClickCallback;useEffect(()=>{const hot = hotRef.current.hotInstance;const exportPlugin = hot.getPlugin('exportFile');buttonClickCallback=()=>{const exportedBlob = exportPlugin.exportAsBlob('csv',{bom:false,columnDelimiter:',',columnHeaders:false,exportHiddenColumns:true,exportHiddenRows:true,mimeType:'text/csv',rowDelimiter:'\r\n',rowHeaders:true});
console.log(exportedBlob);};});return(<><HotTableref={hotRef}data={[['A1','B1','C1','D1','E1','F1','G1'],['A2','B2','C2','D2','E2','F2','G2'],['A3','B3','C3','D3','E3','F3','G3'],['A4','B4','C4','D4','E4','F4','G4'],['A5','B5','C5','D5','E5','F5','G5'],['A6','B6','C6','D6','E6','F6','G6'],['A7','B7','C7','D7','E7','F7','G7'],]}colHeaders={true}rowHeaders={true}hiddenRows={{rows:[1,3,5],indicators:true}}hiddenColumns={{columns:[1,3,5],indicators:true}}height="auto"autoWrapRow={true}autoWrapCol={true}licenseKey="non-commercial-and-evaluation"/><divclassName="controls"><buttonid="export-blob"onClick={(...args)=>buttonClickCallback(...args)}>Export as a Blob</button></div></>);};
Export as a string
Open a console in browser developer tools to see the result for the below example.
import{ useRef, useEffect }from'react';import{ HotTable }from'@handsontable/react';import{ registerAllModules }from'handsontable/registry';import'handsontable/dist/handsontable.full.min.css';// register Handsontable's modulesregisterAllModules();exportconstExampleComponent=()=>{const hotRef =useRef(null);let buttonClickCallback;useEffect(()=>{const hot = hotRef.current.hotInstance;const exportPlugin = hot.getPlugin('exportFile');buttonClickCallback=()=>{const exportedString = exportPlugin.exportAsString('csv',{bom:false,columnDelimiter:',',columnHeaders:false,exportHiddenColumns:true,exportHiddenRows:true,rowDelimiter:'\r\n',rowHeaders:true});
console.log(exportedString);};});return(<><HotTableref={hotRef}data={[['A1','B1','C1','D1','E1','F1','G1'],['A2','B2','C2','D2','E2','F2','G2'],['A3','B3','C3','D3','E3','F3','G3'],['A4','B4','C4','D4','E4','F4','G4'],['A5','B5','C5','D5','E5','F5','G5'],['A6','B6','C6','D6','E6','F6','G6'],['A7','B7','C7','D7','E7','F7','G7'],]}colHeaders={true}rowHeaders={true}hiddenRows={{rows:[1,3,5],indicators:true}}hiddenColumns={{columns:[1,3,5],indicators:true}}height="auto"autoWrapRow={true}autoWrapCol={true}licenseKey="non-commercial-and-evaluation"/><divclassName="controls"><buttonid="export-string"onClick={(...args)=>buttonClickCallback(...args)}>Export as a string</button></div></>);};
Available methods
TIP
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable component, and reading its hotInstance property.
This is required to prepare a predefined settings object. We currently allow for only 'csv' to be used.
options Object
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:
bom Boolean
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.