I have been using a lightning component, on clicking download button. New tab is opened which hit to the vf page url which downloads an excel.
Can we use some other steps of redirection so that the UI remains same and excel gets downloaded.
In VF page, we have wrapper which gets filled by apex class. We dont need to show data in UI. Just one download button to get data.
Thanks
Best Answer
This is an interesting scenario. In past, I have used download.js to trigger file download from JavaScript.
So I have tried to use the same concept here to download the excel file upon clicking of a button in Lightning UI.
The main idea is to convert the Excel into Base64 encoded String and pass it to the download method of download.js. Which will show the file download window upon the same screen.
Here are my code and screecap in action.
Lightning Component Markup
Lightning Component Controller
Apex Class ExcelController
VF Page to generate Excel
Apex Class contactquery used for excel generation
Screencap in action