ERROR in node_modules/exceljs/index.d.ts(1648,34): error TS2503: Cannot find namespace 'NodeJS'.
phanbien9x opened this issue · comments
My application can not start after integrated exceljs. I use angular 7. I checked on node_modules/exceljs/index.d.ts but there are not error. I tried to run example with angular 6 then it work. Please let me know how to implement exceljs in angular 7. Advanced thanks!
I use:
"exceljs": "^2.0.1",
"file-saver": "^2.0.2",
"@angular/cli": "^7.3.0",
"@types/node": "^12.7.5",
I have the same issue.
The other import
import * as Excel from "exceljs/dist/exceljs.min.js";
Fixes the issue, but then you don't get the types.
Changing the version of @types/node to "@types/node": "^10.12.0" works for me.
I have the same issue.
The other import
add tsconfig.json below code
"compilerOptions" :{
"exceljs": [
"node_modules/exceljs/dist/exceljs.min.js"
]
}
I tried all of your suggestion but it only work when I use "workbook" imported by @sasapet way like this:
const workbook = new Excel.Workbook();
Thank all of you to help me! :)
Instead of importing
Use it in the following way in your function:
const Excel = require('exceljs');
Example:
// Excel exporter
ExportToExcel(Header, ReportName): void {
// Excel object
const Excel = require('exceljs');
// Create workbook
const workbook = new Excel.Workbook();
// Create worksheet
const worksheet = workbook.addWorksheet(ReportName);
// Title row
const titleRow = worksheet.addRow([ReportName]);
// Customize Title row
titleRow.font = { name: 'Helvetica Neue', family: 4, size: 16};
// Export to file
workbook.xlsx.writeBuffer().then((data) => {
FService.saveAs(new Blob([data]), ReportName + '_export_' + new Date().getTime() + '.xlsx');
});
}
update "@types/node"-dependency" in your devDependencies to the latest version.
"@types/node": "~12.12.14",
I have the same issue.
The other import
import * as Excel from "exceljs/dist/exceljs.min.js";
Fixes the issue, but then you don't get the types.
I faced this issue and this solution works for me
It may help - https://www.ngdevelop.tech/export-to-excel-in-angular-6/
solution without the change in the tsConfig file
this method does not support an array of objects or objects, but it does support an array or an array of arrays.
if you have used excelJs methods with objects or an array of objects this problem will occur.
u can use a function to transfer the object to array :
- Object.values(obj)