我有JSONObjects数组,像这样
[
{"name":"John", "city": "Seattle"},
{"name":"Mike", "city": "Los Angeles"},
{"name":"Zach", "city": "New York"}
]
当我使用下面给出的代码时,它不起作用
_export: function(records,opts) {
var XLSX = xlsx;
var fileName = opts.split(".")[2]
var workSheet = XLSX.utils.json_to_sheet(records);
console.log("THis is Worksheet",workSheet);
var wb = XLSX.utils.book_new();
console.log("THis is workbook",wb)
XLSX.utils.book_append_sheet(wb, workSheet, fileName);
var bin = XLSX.write(wb, {bookType:'xlsx',type: "binary"});
return new Blob([this._binStr2ArrBuff(bin)], { type: "" });
},
},
我使用的是sheetjs 0.9.11版本,只是想检查一下将它们导出到excel的任何方法,我从最近两天就被困在这里。 任何帮助将不胜感激
答案 0 :(得分:0)
我认为您必须使用XLSX.writeFile(wb, 'book.xlsx')
来导出Excel文件。
替换此代码:
var bin = XLSX.write(wb, {bookType:'xlsx',type: "binary"});
return new Blob([this._binStr2ArrBuff(bin)], { type: "" });