Downloading Excel file xlsx in Angularjs and WebApi

后端 未结 5 800
离开以前
离开以前 2021-01-31 11:52


I am working on a task, in which I have to download a report in xlsx format. The report file is generated successfully from server, and is received on client side as well.

5条回答
  •  旧巷少年郎
    2021-01-31 12:24

    first install these module

    import * as Excel from 'exceljs';
    import * as fs from 'file-saver';
    

    In your function write these

     const workbook = new Excel.Workbook();
      var worksheet =  workbook.addWorksheet('sheet');
      worksheet.columns = [
        { header: 'Id', key: 'id', width: 10 },
        { header: 'Name', key: 'name', width: 32 }
      ];
     var buff = workbook.xlsx.writeBuffer().then(function (data) {
        var blob = new Blob([data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
        fs.saveAs(blob, "publications.xlsx");
      });
    

    Fs is used to access file system and download file. You can also insert img https://www.npmjs.com/package/exceljs#images

提交回复
热议问题