Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]);
like image 566
rafi muhammad Avatar asked Jun 30 '26 21:06

rafi muhammad


2 Answers

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.

like image 93
Pengyy Avatar answered Jul 02 '26 11:07

Pengyy


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

like image 37
Karim Avatar answered Jul 02 '26 09:07

Karim