3
  • I am trying to read the content of a csv file by taking an input in an Microsoft Office Excel add-in.
  • Facing the error as taskpane.js:84 TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'.
  • HTML
<form>
<input type="file" id="csv-file">
<button type="submit" id="csv-data">Submit</button>
</form>
  • JS
async function import_from_csv() {
  try {
    var file = document.getElementById("csv-file");
    var files = file[0];
    var reader = new FileReader();
    reader.readAsText(files);
    reader.onload = function (event) {
      var csv = event.target.result;
      var data = $.csv.toArrays(csv);
      console.log("Data =", data);
    };
  } catch (error) {
    console.error(error);
  }
}
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Lav Sharma
  • 327
  • 1
  • 5
  • 23
  • First of all, there is no Office.js in your code, so remove that from the title and remove the office-js tag. You may be using it somewhere else in your project, but it has nothing to do with your problem. Secondly, the `getElementById` method returns an Element object, not an array; so the next line that treats it as an array doesn't make sense. That's probably why `files` is not a Blob, as the error message is telling you. – Rick Kirkham Aug 13 '22 at 06:35

0 Answers0