简体   繁体   English

添加test.ts文件时找不到名称“ XLSX”

[英]Cannot find name 'XLSX' when adding test.ts file

I have added xlsx.full.min.js file. 我添加了xlsx.full.min.js文件。

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]);

For typescript, you have to install @types/xlsx by npm install @types/xlsx --save . 对于打字稿,您必须安装@types/xlsx通过npm install @types/xlsx --save

Import it this way: 这样导入:

import * as XLSX from 'xlsx';

this is issue on their site. 这是他们网站上的问题

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'); 您必须使用npm install xlsx安装XLSX模块,然后必须在代码之上初始化XLSX变量if(typeof require !== 'undefined') XLSX = require('xlsx'); . Check the library details: https://www.npmjs.com/package/xlsx 检查库详细信息: https : //www.npmjs.com/package/xlsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM