Sunday, November 20, 2016

Export a list of array to Excel or CSV in Javascript


If you wonder how hard it is to generate an excel or csv in javascript, stop wonder. It is very easy and you don't even have to use a framework to do it. But if you prefer to have a powerful customization, then yes, go for a framework.

Below are the step on how to do it.
(Note that, it will come out as plain excel and csv file. This will be useful when you only need the data inside the excel or csv file for import purpose).

For Chrome: 

HTML (Create an onclick button)


Javascript


* For those who are using Mozilla Firefox, you may consider to use the method below.
   (The above method not working well in my Mozilla Firefox)

For Mozilla Firefox:

HTML (Create an onlick button)


Javascript

3 comments

Hi, I want to ask how to export as xlsx file instead of csv file?

This comment has been removed by the author.

Just changed the .csv of this line `excel_file.setAttribute('download', 'Visitor_History.csv')` to .xls

Done!


EmoticonEmoticon