CSV Export
A set of functions to convert data into CSV values, and enable a browser download of the CSV data.
Installation
Install the module
pnpm install @woocommerce/csv-export --save
Usage
onClick = () => {
const name = generateCSVFileName( 'revenue', { interval: 'month' } );
const data = generateCSVDataFromTable( headers, rows );
downloadCSVFile( name, data );
}
Generates a CSV string from table contents
Returns: String
- Table contents in a CSV format
Param | Type | Description |
---|
headers | Array.<Object> | Object with table header information |
rows | Array.Array.<Object> | Object with table rows information |
generateCSVFileName([name], [params]) ⇒ String
Generates a file name for CSV files based on the provided name, the current date
and the provided params, which are all appended with hyphens.
Returns: String
- Formatted file name
Param | Type | Default | Description |
---|
[name] | String | '' | Name of the file |
[params] | Object | {} | Object of key-values to append to the file name |
downloadCSVFile(fileName, content)
Downloads a CSV file with the given file name and contents
Param | Type | Description |
---|
fileName | String | Name of the file to download |
content | String | Contents of the file to download |