I wrote as in demo,but result in saveAs is not defined.
var data = [
{ name: "Barack Obama", pres: 44 },
{ name: "Donald Trump", pres: 45 }
];
/* generate a worksheet */
var ws = XLSX.utils.json_to_sheet(data);
/* add to workbook */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Presidents");
/* write workbook (use type 'array' for ArrayBuffer) */
var wbout = XLSX.write(wb, {bookType:'xlsx', type:'array'});
/* generate a download */
saveAs(new Blob([wbout],{type:"application/octet-stream"}), "sheetjs.xlsx");
saveAs is currently provided by the FileSaver shim: https://unpkg.com/[email protected]/FileSaver.min.js . You can also manually generate a download using URL.createObjectURL and clicking a link. See https://jsfiddle.net/ve9g38kv/
/* create object URL */
var blob = new Blob([wbout],{type:"application/octet-stream"});
var url = URL.createObjectURL(blob);
/* create new link and add to document */
var link = document.createElement("a");
link.download = "sheetjs.xlsx";
link.href = url;
document.body.appendChild(link);
/* click the link */
link.click();
/* cleanup */
document.body.removeChild(link);
URL.revokeObjectURL(url);
Most helpful comment
saveAsis currently provided by the FileSaver shim: https://unpkg.com/[email protected]/FileSaver.min.js . You can also manually generate a download usingURL.createObjectURLand clicking a link. See https://jsfiddle.net/ve9g38kv/