部署后ExcelJS不会下载,但不会显示任何错误

时间:2019-06-11 06:50:59

标签: exceljs

我已经使用exceljs在正在处理的应用程序中导出了一些报告,并且在开发中效果很好。但是在天蓝色地部署它后,它不起作用。而且它没有显示任何错误。该应用程序是用angular 6编写的。有人能指出我在做什么错吗?谢谢。

  exportToExcel() {
    //validation works fine
    if (this.validateSearch() == false) {
      return;
    }
    //Excel Title, Header, Data
    const title = 'Company name';
    const title1 = 'report name';

    const subTitle = 'As at Date :' + 
    this.registerDetailToDate.toLocaleDateString();

    const header = ['Travel Partner Code', 'Travel Partner Name', 'Owner Name', 'Mobile Number', 'Address', 'TP Status', 'Vehicle Number', 'Vehicle', ' Vehicle Status ']

    let data = [];
    for (let i = 0; i < this.driver.length; i++) {
      data.push([this.driver[i].driverCode, this.driver[i].driverName, 
         this.driver[i].ownerName, this.driver[i].mobileNumber, 
         this.driver[i].address, this.driver[i].driverStatusName, 
         this.driver[i].vehicleNumber, 
         this.driver[i].vehicleTypeName 
         + ' ' + this.driver[i].vehicleMakeName 
         + ' ' + this.driver[i].vehicleModelName, 
         this.driver[i].vehicleStatusName])
    }

    //Create workbook and worksheet
    let workbook: Workbook = new Workbook();
    let worksheet = workbook.addWorksheet('Travel Partner Summary Report');
    //Add Row and formatting
    let titleRow = worksheet.addRow([title]);
    let titleRow1 = worksheet.addRow([title1]);

    titleRow.font = { name: 'Comic Sans MS', family: 4, size: 8, bold: true 
    }
    worksheet.addRow([]);
    let subTitleRow = worksheet.addRow([subTitle])

    //worksheet.mergeCells('A1:D2');
    //Blank Row 
    worksheet.addRow([]);
    //Add Header Row
    let headerRow = worksheet.addRow(header);

    // Cell Style : Fill and Border
   headerRow.eachCell((cell, number) => {
     cell.fill = {
       type: 'pattern',
       pattern: 'solid',
       fgColor: { argb: 'FF00FF00' },
       bgColor: { argb: 'FF0000FF' }
     }
     cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, 
     bottom: { style: 'thin' }, right: { style: 'thin' } }
   })

   // Add Data and Conditional Formatting
   data.forEach(d => {
      let row = worksheet.addRow(d);
   }
   );
    worksheet.getColumn(1).width = 20;
    worksheet.getColumn(2).width = 20;
    worksheet.getColumn(3).width = 20;
    worksheet.getColumn(4).width = 20;
    worksheet.getColumn(5).width = 20;
    worksheet.getColumn(6).width = 20;
    worksheet.getColumn(7).width = 20;
    worksheet.getColumn(8).width = 20;
    worksheet.getColumn(9).width = 20;
    worksheet.addRow([]);

    //Generate Excel File with given name
    workbook.xlsx.writeBuffer().then((data) => {
        let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        var filename = "Travel Partner Summary Report - " + (new Date()).toUTCString() + ".xlsx";
        fs.saveAs(blob, filename);
    })
  }

0 个答案:

没有答案