在Angular里用,用纯js plugin插件生成excel报表,用到如下插件,
// Browser save file (compatibility) (click to show)
https://github.com/SheetJS/js-xlsx
https://github.com/eligrey/FileSaver.js
js-xlsx, 这个插件真的非常的强大,有免费社区版和Pro Version收费版,如果对所下载的报表的样式要求不高的话,用社区版完全可以实现需求,如果对样式有特殊要求,并且还不想用Pro Version不想花钱的话,也可以考虑用社区版填充数据,之后在excel里写vba宏来实现样式的定制化!!
- Browser save file (compatibility) (click to show)
XLSX.writeFile techniques work for most modern browsers as well as older IE. For much older browsers, there are workarounds implemented by wrapper libraries.
FileSaver.js implements saveAs. Note: XLSX.writeFile will automatically call saveAs if available.
/* bookType can be any supported output type */
var wopts = { bookType:’xlsx’, bookSST:false, type:’array’ };
var wbout = XLSX.write(workbook,wopts);
/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([wbout],{type:”application/octet-stream”}), “test.xlsx”);