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
  }

 

posted @ 2019-08-29 10:02  开尔  阅读(11607)  评论(0编辑  收藏  举报