blob格式導出文件


最近在做blob流導出相關功能,其中需要導出excel、csv、word、zip壓縮文件之類的,在導出excel和word中需要知道對應的content-type屬性,正好看到下面這篇文章,感覺挺好的就記錄一下

 

后綴 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代碼

 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
  }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM