1、HTML5新特性
<a href="要下载文件的路径" download="要下载文件的名称"></a>
2、下载方法
window.open('文件路径');
或 window.location.href = '文件路径';
3、解决文件名为中文下载出现_____.doc的问题(angular中)
download() {
let url = `路径`;
this.http.request('GET',url,{
responseType: "arraybuffer"
}).subscribe((val:any)=>{
let blob = new Blob([val], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
let objectUrl = URL.createObjectURL(blob);
let filename = '文件名';
let aDownload = $("<a><span class='downloadFile'></span></a>").attr("href",objectUrl).attr('download',filename);
$("body").append(aDownload);
$(".downloadFile").click();
aDownload.remove();
});
}