NO.1
摘自文章:
https://blog.csdn.net/weixin_43833570/article/details/97010455
前端处理数据,导出excel
var uInt8Array = new Uint8Array(content); //先将返回的二进制数组转化为js的二进制数组
let blob=new Blob([uInt8Array],{type:"application/vnd.ms-excel"});//然后创建blob对象,文件类型设置为excel的类型
let blobURL = window.URL.createObjectURL(blob);//然后创建一个可访问的URL
let tempLink = document.createElement('a');//创建a标签去下载
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', fileName+".xlsx");
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank');
}
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
NO.2
摘自文章:
https://code-examples.net/zh-TW/q/182e049
var downloadBlob, downloadURL;
downloadBlob = function(data, fileName, mimeType) {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName, mimeType);
setTimeout(function() {
return window.URL.revokeObjectURL(url);
}, 1000);
};
downloadURL = function(data, fileName) {
var a;
a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style = 'display: none';
a.click();
a.remove();
};
downloadBlob(myBinaryBlob, 'some-file.bin', 'application/octet-stream');