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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)