Angular 5 和 ExcelJS [英] Angular 5 and ExcelJS

查看:29
本文介绍了Angular 5 和 ExcelJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用并遵循此库中的示例: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');
   }
}

这篇关于Angular 5 和 ExcelJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆