1. 程式人生 > >在Angular裡用,純js plugin js-xlsx外掛生成excel報表

在Angular裡用,純js plugin js-xlsx外掛生成excel報表

在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”);