如何在函数.onload中返回某些内容

时间:2018-10-25 19:51:18

标签: javascript js-xlsx sheetjs

我正在尝试使用SheetJS js-xlsx导入Excel文件,但我不知道如何返回变量工作簿。谢谢!

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

0 个答案:

没有答案