rafi muhammad
rafi muhammad

Reputation: 192

Cannot find name 'XLSX' when adding test.ts file

I have added xlsx.full.min.js file.

here is my code

var workbook =  XLSX.read(data, { type: 'binary' });
var sheetName = workbook.SheetNames[0];
var excelData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);

Upvotes: 2

Views: 7332

Answers (2)

Pengyy
Pengyy

Reputation: 38171

For typescript, you have to install @types/xlsx by npm install @types/xlsx --save.

Import it this way:

import * as XLSX from 'xlsx';

this is issue on their site.

Upvotes: 7

Karim
Karim

Reputation: 218

You have to install the XLSX module using npm install xlsx then you have to intialize XLSX variable on top of your code if(typeof require !== 'undefined') XLSX = require('xlsx');. Check the library details: https://www.npmjs.com/package/xlsx

Upvotes: 3

Related Questions