0

I'm trying to import an excel file using SheetJS js-xlsx and I don't know how to return the variable workbook. Thanks!

var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer
function handleFile(e) {
  var files = e.target.files, f = files[0];
  var reader = new FileReader();
  reader.onload = function(e) {
    var data = e.target.result;
    if(!rABS) data = new Uint8Array(data);
    var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'});

    /* DO SOMETHING WITH workbook HERE */
  };
  if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f);
}
input_dom_element.addEventListener('change', handleFile, false);
S Bogdan
  • 19
  • 2
  • 1
    What do you mean return? You can not return from an asynchronous call. You do the work where the comment says to work with it..... https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – epascarello Oct 25 '18 at 19:55
  • Thanks! Sorry for the dummy question! – S Bogdan Oct 25 '18 at 20:12

0 Answers0