1
votes

I am using xlsx-style npm module in my angular2 application for creating excels dynamically. Reason for using xlsx-style rather than xlsx module is because I need to style the cells which is not possible using xlsx.

I have copied the xlsx.full.min.js from dist folder(from node_modules/xlsx-style) to assets folder and attached as a scritp tag to html page.

Ref : how to use SheetJS (js-xlsx) in angular 2

I have imported the module into my component for namespace based access into my code.

declare var XLSX : any;

While building the app using ng build, I get the following error : Cannot find namespace 'XLSX'

Using @angular/cli @latest (Webpack)

2
Why don't you use ts-xlsx , It's what you are looking for, here's the link: github.com/DxCx/ts-xlsx you can install it also by npm like this: npm install --save ts-xlsx good luck - user3909311

2 Answers

0
votes

You can easily declare the module in some file e.g. globals.d.ts:

declare module "XLSX"; 

More

Covered in the migration guide : https://basarat.gitbooks.io/typescript/docs/types/migrating.html

0
votes

You can declare:

import { XLSX } from 'xlsx-style';