Export to Excel on Angular 4

前端 未结 5 1857
春和景丽
春和景丽 2021-02-13 05:55

I have a data table that is dynamically populated using Angular 4. I would like to export the table to excel. How can I achieve this in Angular 4. I\'m looking for .xls and not

5条回答
  •  隐瞒了意图╮
    2021-02-13 06:02

    For those who are still looking for a working answer.

    public export() {
        const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.myDataModels);
        /* generate workbook and add the worksheet */
        const wb: XLSX.WorkBook = XLSX.utils.book_new();
        XLSX.utils.book_append_sheet(wb, worksheet, 'Sheet1');
        /* save to file */
        XLSX.writeFile(wb, this.createFileName());
    }
    

    This will save as an xlsx file automatically Got this from https://github.com/SheetJS/js-xlsx/tree/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/demos/angular2

提交回复
热议问题