exportToCSV
Exports an array of objects to a CSV file and triggers a browser download.Function Signature
Parameters
Array of objects to export. Each object represents a row in the CSV file.
Array of header definitions that map object keys to column labels.Each header object should have:
key(string): The property name in the data objectslabel(string): The column header label to display in the CSV
Name of the file without extension. A timestamp (YYYY-MM-DD) and
.csv extension will be automatically appended.Behavior
- Automatically escapes values containing commas, quotes, or newlines
- Handles
nullandundefinedvalues by converting them to empty strings - Appends current date (YYYY-MM-DD format) to the filename
- Triggers browser download automatically
- Creates UTF-8 encoded CSV files
Usage Examples
Exporting Transaction Data
Exporting Portfolio Holdings
Handling Special Characters
The function automatically handles values with special characters:CSV Output Format
The generated CSV file will have:- First row: Header labels from the
labelproperty - Subsequent rows: Data values from the
keyproperties - Proper escaping for special characters
- UTF-8 encoding with BOM for Excel compatibility
Related Functions
This utility is built on top of internal helper functions:convertToCSV(data, headers): Converts array to CSV string formatdownloadCSV(csvContent, filename): Triggers browser download
The file will be downloaded to the user’s default Downloads folder. The browser’s download behavior may vary based on user settings.
