WasiF
WasiF

Reputation: 28847

How to use exceljs in angular 6

When I tried to use exceljs in Angular-6 like so

import * as excel from 'exceljs'

createExcel() {
  let workbook = new excel.Workbook()
}

even I just initialize a class and got this error. If I comment out this line let workbook = new excel.Workbook() then error gone

./node_modules/fs-constants/browser.js Module not found: Error: Can't resolve 'constants' in 'D:\Developer\spire-client\node_modules\fs-constants'

enter image description here

Upvotes: 4

Views: 12159

Answers (2)

Abhishek Kumar
Abhishek Kumar

Reputation: 1040

Import like this

import * as Excel from "exceljs/dist/exceljs.min.js";

and declare

const workbook = new Excel.Workbook();

It will work.

Upvotes: -1

Chandu
Chandu

Reputation: 2129

You could import it as follow

import * as Excel from 'exceljs';

after that, you can use Exceljs:

const myWorkbook = new Excel.Workbook()

or

import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";

let workbook: ExcelProper.Workbook = new Excel.Workbook();

As long as you just use the import from exceljs for type definitions and only use functions from the import from exceljs/dist/exceljs.min.js, the app will run just fine and you still get type safety.

ref: https://www.npmjs.com/package/exceljs#create-a-workbook https://github.com/guyonroche/exceljs/issues/348#issuecomment-320690232

Upvotes: 11

Related Questions