eranhd/Anti-Drug-Jerusalem

Generate csv in client

Closed this issue · 2 comments

var data = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]];
var csvContent = "data:text/csv;charset=utf-8,";
data.forEach(function(infoArray, index){

   dataString = infoArray.join(",");
   csvContent += index < data.length ? dataString+ "\n" : dataString;
});
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
link.setAttribute('style','display:block;width:200px;height:200px;font-size:50px;')
document.body.appendChild(link); // Required for FF

link.click(); // This will download the data file named "my_data.csv".

הוטמע בפרויקט