https://docs.sheetjs.com/docs/demos/network#xmlhttprequest
var filename = 'Test.xlsx';
var req = new XMLHttpRequest();
req.open('GET', filename, true);
req.responseType = 'arraybuffer';
req.onload = function (e) {
//兼容IE,需把type改为binary,并对req.response进行转化
var workbook = XLSX.read(arrayBufferToBinaryString(req.response), {
type: 'binary'
});
console.log(workbook);
}
req.send();
//ArrayBuffer转BinaryString转BinaryString
function arrayBufferToBinaryString(data) {
var o = '',
l = 0,
w = 10240;
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
return o;
}