Reactjs TypeError:无法执行';readAsBinaryString';在';文件读取器';:参数1的类型不是';水滴';
我该怎么办? 我已经用npm下载了xlsxReactjs TypeError:无法执行';readAsBinaryString';在';文件读取器';:参数1的类型不是';水滴';,reactjs,Reactjs,我该怎么办? 我已经用npm下载了xlsx import React from "react" import XLSX from "xlsx" const Function = () => { const onClick = () => { document.getElementById('selectedFile').click(); } const excelExport = (event) =&g
import React from "react"
import XLSX from "xlsx"
const Function = () => {
const onClick = () => {
document.getElementById('selectedFile').click();
}
const excelExport = (event) =>{
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var fileData = reader.result;
var wb = XLSX.read(fileData, {type : 'binary'});
wb.SheetNames.forEach(function(sheetName){
var rowObj =XLSX.utils.sheet_to_json(wb.Sheets[sheetName]);
console.log(JSON.stringify(rowObj));
})
};
reader.readAsBinaryString(input.files[0]);
}
return(
<>
<div className="function">
<input type="file" id="selectedFile" onClick={excelExport}/>
<input type="button" className="select-function" value="upload" onClick={onClick} />
<input type="button" className="select-function" value="add"/>
<input type="button" className="select-function" value="delete"/>
</div>
</>
)
}
export default Function
TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob'.