Javascript使用SheetJS读取服务器上的Excel文件 [英] Javascript Read Excel file on server with SheetJS
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;
}
标签:读取,req,Excel,SheetJS,var,new,data
From: https://www.cnblogs.com/vvull/p/17029893.html