Export to Excel on Angular 4

前端 未结 5 1863
春和景丽
春和景丽 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:08

    You can only use xlsx library to write and save excel file at the same time using XLSX.writeFile()

    exportExcel(data: any[]){
       const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(data);
       const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
       XLSX.writeFile(workbook, 'my_file.xls', { bookType: 'xls', type: 'buffer' });
    }
    

提交回复
热议问题