如何在JavaScript或jQuery中从xls / xlsx获取标头?

时间:2018-01-04 05:22:07

标签: javascript jquery html excel

如何在不解析整个文件的情况下,只从JavaScript或jQuery中的xls / xlsx文件中获取标头值? XLSX.read(data, { type: 'binary' });花费了太多时间进行解析。但我只需要浏览器端的标题。我将在服务器端完成剩下的工作。谢谢。

1 个答案:

答案 0 :(得分:0)

var url = "your excel file.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(e) {
  var arraybuffer = oReq.response;
  var data = new Uint8Array(arraybuffer);
  var arr = new Array();
  for(var i = 0; i != data.length; ++i) {
    arr[i] = String.fromCharCode(data[i]);
  }
  var bstr = arr.join("");
  var workbook = XLSX.read(bstr, {type:"binary"});
  var t = workbook.SheetNames;
}
oReq.send();