代码之家  ›  专栏  ›  技术社区  ›  Sourabh Banka

从“ExcelJS”导入Excel引发浏览器类型错误:无法读取未定义的属性“Prototype”

  •  3
  • Sourabh Banka  · 技术社区  · 7 年前

    我正在使用react构建我的网页。我想把我的Reducer的存储数据下载到一个XLXS文件中。因为我正在使用 exceljs 包裹。 我已经安装了 卓越 使用 npm i exceljs

    但当我试图进口 卓越 在我的组件中 TypeError: Cannot read property 'prototype' of undefined 在屏幕上。

    我正在使用命令导入 import Excel from "exceljs"; .

    请查看屏幕截图,以获得我在屏幕上看到的更好的错误视图。 enter image description here enter image description here

    我的package.json是:

    {
      "name": "xxxxxxx_xxxxx",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "exceljs": "^1.6.0",
        "react": "^16.4.1",
        "react-dom": "^16.4.1",
        "react-intl": "^2.4.0",
        "react-redux": "^5.0.7",
        "react-router": "^4.3.1",
        "react-router-dom": "^4.3.1",
        "react-scripts": "1.1.4",
        "redux": "^4.0.0",
        "redux-logger": "^3.0.6",
        "redux-thunk": "^2.3.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build:langs": "NODE_ENV='production' ./node_modules/.bin/babel src --out-dir lib",
        "build:locale": "NODE_ENV='production' babel-node scripts/translator.js",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      },
      "devDependencies": {
        "babel-cli": "^6.26.0",
        "babel-plugin-react-intl": "^2.4.0"
      }
    }
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   bwalshy    7 年前

    似乎ExcelJS的导出对于浏览器来说有点奇怪。我做了以下工作:

    import Excel from "exceljs/dist/es5/exceljs.browser";
    

    然后你可以用 Excel 不管你喜欢什么。即:

    console.log('excel', Excel);  // Check that it exists
    var workBook = new Excel.Workbook(); // Make a new Workbook
    
        2
  •  0
  •   Ravi    7 年前

    我用以下方法来实现它:

    从“excel js/dist/exceljs.min.js”导入*为excel;

    而不是

    从“exceljs/dist/es5/exceljs.browser”导入excel;

    推荐文章