export function download(file, name) {
let blob;
if (file.data instanceof Blob) {
blob = file.data;
} else {
blob = new Blob([file.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' });
}
const headerDisposition = (file.headers['Content-Disposition'] || '').match(/filename=(.*\.(xlsx|docx))/);
const filename = headerDisposition ? headerDisposition[1] : name;
const url = window.URL.createObjectURL(blob);
if ('msSaveOrOpenBlob' in navigator) {
// Microsoft Edge and Microsoft Internet Explorer 10-11
window.navigator.msSaveOrOpenBlob(blob, filename);
} else {
const eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
eleLink.href = url;
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
}
}
js文件导出下载
最新推荐文章于 2024-08-26 14:54:22 发布
2864

被折叠的 条评论
为什么被折叠?



