当前位置: 首页 > news >正文

文件流导出文件

// 下载excel
export const downloadFile = (fileStream, fileName) => {if (window.navigator.msSaveBlob) {try {window.navigator.msSaveBlob(fileStream, fileName);} catch (e) {console.log(e);}} else {const url = window.URL || window.webkitURL;const bUrl = url.createObjectURL(fileStream);let a = document.createElement("a");a.style.display = "none";a.href = bUrl;a.download = decodeURIComponent(fileName);document.body.appendChild(a);a.click();document.body.removeChild(a);url.revokeObjectURL(bUrl);}
};

使用downloadFile(res, `默认文件.xlsx`);

res是后端返回文件流,默认文件.xlsx是文件名   .xlsx是后缀名

// 获取文件类型
export function getFileType(file) {const type = file.type || "";const name = file.name || "";if (type.includes("word")) {return "doc";} else if (type.includes("excel") || type.includes("spreadsheetml.sheet")) {return "excel";} else if (type === "text/plain") {return "txt";} else if (type === "application/pdf") {return "pdf";} else if (type === "text/html") {return "html";} else if (type === "text/markdown" || name.includes(".md")) {return "md";} else {return "other";}
}

http://www.lryc.cn/news/592532.html

相关文章:

  • spring boot 实战之分布式锁
  • 【Nginx】nginx+lua+redis实现限流
  • docker,防火墙关闭后,未重启docker,导致端口映射失败
  • 产品需求文档(PRD)格式全解析:从 RP 到 Word 的选择与实践
  • 前端性能优化“核武器”:新一代图片格式(AVIF/WebP)与自动化优化流程实战
  • 新手向:图片批量裁剪工具
  • 力扣 hot100 Day48
  • AWS(基础)
  • (nice!!!)(LeetCode 每日一题) 2163. 删除元素后和的最小差值 (贪心+优先队列)
  • #vscode# #SSH远程# #Ubuntu 16.04# 远程ubuntu旧版Linux
  • 网工知识——vlan技术
  • go安装使用gin 框架
  • 在 Jenkins 中使用 SSH 部署密钥
  • mac系统安装、启动Jenkins,创建pytest接口自动化任务
  • 周志华《机器学习导论》第9章 聚类
  • 一文讲清楚React的render优化,包括shouldComponentUpdate、PureComponent和memo
  • 【Lua】闭包可能会导致的变量问题
  • python-pptx 的layout 布局
  • 人工智能概念之九:深度学习概述
  • JavaSE -- 对象序列化和反序列化详细讲解
  • MySQL的关键日志
  • QML vscode语法高亮和颜色区分。
  • 根据用户id自动切换表查询
  • 7月18日总结
  • UNet改进(23):如何用SLCAM模块提升UNet的分割性能
  • Linux C 进程间通信基本操作
  • 对Yii2中开启`authenticator`后出现的跨域问题-修复
  • 高通8255 Android Virtio Virtio-SPI 配置方法
  • 当OT遇见IT:Apache IoTDB如何用“时序空间一体化“技术破解工业物联网数据孤岛困局?
  • RSTP技术