Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 379
WasiF Avatar asked Jan 02 '23 20:01

WasiF


1 Answers

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

like image 198
Chandu codes Avatar answered Jan 08 '23 23:01

Chandu codes