Angular 5 and ExcelJS

2019-04-15 02:49发布

I have been trying to use and following the examples from this library: https://www.npmjs.com/package/exceljs#create-a-workbook


I am using it on Angular 5. I always get an error

graceful-fs.js:166 Uncaught TypeError: Cannot read property 'prototype' of undefined
    at patch (graceful-fs.js:166)

From these lines of my code:

import * as Excel from 'exceljs';

export class ExcelHandler {
   public testExcelJs() {
      var workBook: Excel.Workbook;
      var workSheet: Excel.Worksheet;

      workBook = new Excel.Workbook();
      workSheet = workBook.addWorksheet(sheetName);
   }
}



Thanks.

1条回答
Animai°情兽
2楼-- · 2019-04-15 03:19

Seems the npm example is given in node definitions and you are using typescript, a quick workaround would be to install node types so that you needn't find equivalent typescript syntax everytime, ie npm install --save-dev @types/node, with this done, node definitions would be added to the IDE and would also resolve compilation issues.

Now your file could be like this:

var Excel = require('exceljs');


export class ExcelHandler {
   public testExcelJs() {


      var workBook = new Excel.Workbook();
      var workSheet = workBook.addWorksheet('my-worksheet');
   }
}
查看更多
登录 后发表回答