thelonglqd
thelonglqd

Reputation: 1862

Reading file used XLSX.js with React got TypeMissMatchError on Internet Explorer 11

I got the dialog error TypeMissMatchError on Internet Exlorer 11 after choosing file to read.

enter image description here

Below is my code to read file:

onChangeFile = event => {
    event.stopPropagation();
    event.preventDefault();
    const file = event.target.files[0];
    const reader = new FileReader();
    reader.addEventListener("load", e => {
      const data = e.target.result;
      let readedData = XLSX.read(data, { type: "array", cellDates: true, dateNF: "yyyy-mm-dd;@" });

      const wsname = readedData.SheetNames[0];
      const ws = readedData.Sheets[wsname];
      const dataParse = XLSX.utils.sheet_to_json(ws, { header: 1, raw: false, dateFN: "yyyy-mm-dd", blankrows: false, defval: "" });
      this.validateImportedData(dataParse);
      this.upload.value = "";
    });
    reader.readAsArrayBuffer(file);
  };

Any idea about this error ?

Upvotes: 0

Views: 146

Answers (1)

Deepak-MSFT
Deepak-MSFT

Reputation: 11335

I try to check your code and found that your code has => arrow functions.

Arrow function expressions is not supported by the IE browser.

This can be the possible reason for that error.

You need to transpile your code from ES 6 to ES 5. Then it can work in the IE browser.

You can try to use Babeljs to transpile the code. It can help you to solve the issue.

Upvotes: 1

Related Questions