+ Start a Discussion
srinath vallabsrinath vallab 

Download as csv in inline Visualforce page/Lightning component

Hi Salesforce Developers,
I have an inline Visualforce page on account detail page. And there is lightning component inside this VF page. There is some table of data and a "Download" button to download the given table as csv/excel. On button click, I tried to create CSV file using below code. 
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
hiddenElement.target = '_self'; //
hiddenElement.download = 'ExportData.csv';  // CSV file Name* you can change it.[only name not .csv]
document.body.appendChild(hiddenElement); // Required for FireFox browser
hiddenElement.click(); // using click() js function to download csv file
This is working in classic but not in Lightning. Below error is shown in lightning.
Error shown in Lightning
Any help would be much appreciated.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi srinath,

May I request you please refer the below link for reference Download Data as CSV File With JavaScript In Salesforce Lightning Component. Hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Rahul Kumar
farukh sk hdfarukh sk hd
How to Download data in csv format using Lightning component.

On my blog i have displayed some data to user, User will select the data that user wants to download from the displayed data. Once user select all those record which user wants to export user has to click on download data button and excel in the csv format will get download.

Also i have shown how to show data from related object in csv as well.

Please refer the below link.