admin管理员组文章数量:1391969
I have been struggling with Javascript array data to put it in excel on the client side. I have read this,How to export JavaScript array info to csv (on client side)?
But that is for CSV. I want Excel.
I have been struggling with Javascript array data to put it in excel on the client side. I have read this,How to export JavaScript array info to csv (on client side)?
But that is for CSV. I want Excel.
Share Improve this question asked Nov 23, 2017 at 4:37 kimoduorkimoduor 6148 silver badges17 bronze badges1 Answer
Reset to default 5I got a good answer. It may help someone out there
function excelformat() {
var result_table = [
["Day", "Month", "Year"],
["1", "January", "2016"],
["2", "February", "2016"],
["3", "March", "2016"],
["4", "April", "2016"],
];
var lineArray = [];
result_table.forEach(function(infoArray, index) {
var line = infoArray.join(" \t");
lineArray.push(index == 0 ? line : line);
});
var csvContent = lineArray.join("\r\n");
var excel_file = document.createElement('a');
excel_file.setAttribute('href', 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(csvContent));
excel_file.setAttribute('download', 'Visitor_History.xls');
document.body.appendChild(excel_file);
excel_file.click();
document.body.removeChild(excel_file);
}
本文标签: How to export Javascript array data to excel on the client sideStack Overflow
版权声明:本文标题:How to export Javascript array data to excel on the client side - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744706574a2620875.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论