我有这段代码,我想使用Sheetjs将JSON对象数组导出到excel,我正在使用sheetjs 0.10.1将其填充到excel文件,然后下载它,但是我不知道我在做什么。我遗漏了文件本身没有在浏览器中自动下载。
_export : function(records, path) {
var XLSX = xlsx;
var sheetName = path.split(".")[2];
console.log("Sheeeeeeeeeeeeeeeeet Nameeeeeee ",sheetName);
console.log("XLSSSSSSSSSSS Nameeeeeee ", xlsx);
var workSheet = XLSX.utils.json_to_sheet(records);
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, workSheet, sheetName);
var fileName = XLSX.write(wb, {bookType:'xlsx', type: 'binary'});
return fileName;
}
},
我拥有的json记录就是这样
[
{"name":"John", "city": "Seattle"},
{"name":"Mike", "city": "Los Angeles"},
{"name":"Zach", "city": "New York"}
]
我们非常感谢您的帮助,