问题
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