问题描述
我一直在尝试使用并遵循此库中的示例:https://www.npmjs.com/package/exceljs#create-a-工作簿
I have been trying to use and following the examples from this library: https://www.npmjs.com/package/exceljs#create-a-workbook
我在 Angular 5 上使用它.我总是收到错误
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)
从我的这些代码行:
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.
推荐答案
似乎在节点定义中给出了 npm 示例并且您正在使用打字稿,一个快速的解决方法是安装节点类型,这样您就不需要找到等效的打字稿每次都使用语法,即 npm install --save-dev @types/node
,完成此操作后,节点定义将添加到 IDE 中,也将解决编译问题.
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');
}
}