最近在作blob流導出相關功能,其中須要導出excel、csv、word、zip壓縮文件之類的,在導出excel和word中須要知道對應的content-type屬性,正好看到下面這篇文章,感受挺好的就記錄一下app
後綴 | MIME Type |
.doc | application/msword |
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.xls | application/vnd.ms-excel |
.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.ppt | application/vnd.ms-powerpoint |
.pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
附帶導出excel文件格式的相關js代碼spa
exportFile(data:any, fileName:string) { let blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});//以二進制形式存儲,並轉化爲Excel let now = new Date(); let date = now.getFullYear() + '-' + (now.getMonth() +1) + '-' + now.getDate(); let exportFileName = date + ' ' + fileName + ".xlsx";//自定義導出excel表名稱 saveAs(blob, exportFileName); //使用文件導出插件FileSaver.js }