How to export JavaScript array info to csv (on client side)?

前端 未结 29 1680
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 21:55

I know there are lot of questions of this nature but I need to do this using JavaScript. I am using Dojo 1.8 and have all the attribute info in array, which loo

29条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 22:55

    You can use the below piece of code to export array to CSV file using Javascript.

    This handles special characters part as well

    var arrayContent = [["Séjour 1, é,í,ú,ü,ű"],["Séjour 2, é,í,ú,ü,ű"]];
    var csvContent = arrayContent.join("\n");
    var link = window.document.createElement("a");
    link.setAttribute("href", "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(csvContent));
    link.setAttribute("download", "upload_data.csv");
    link.click(); 
    

    Here is the link to working jsfiddle

提交回复
热议问题