Angular 5 and ExcelJS

泄露秘密 提交于 2019-12-22 01:15:40

问题


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:


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');
   }
}


来源:https://stackoverflow.com/questions/52088876/angular-5-and-exceljs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!