C# 下载模板文件 Excel

后端代码

cs 复制代码
[HttpGet("DownloadExcel")]
  public async Task<dynamic> DownloadExcel(string tmplName)
        {
            var _fileName = "导入表模板.xlsx";
            
            var filePath = @"Files\DownLoad\";
            var NewFile = Path.Combine(filePath, tmplName);
            var stream = new FileStream(NewFile, FileMode.Open);
            return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        }

前端代码 vue 2.0

javascript 复制代码
// 下载导入表模板
    downloadExcel() {
      Axios.get('/api/Excel/DownloadExcel', {
        params: {
          tmplName: 'Excel'
        },
        responseType: 'blob',
      })
          .then(res => {
            const link = document.createElement('a')
            // const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
            const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
            link.style.display = 'none'
            link.href = URL.createObjectURL(blob)
            link.download = 'xxx入表模板.xlsx'
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
          })
          .catch(error => {
            console.log(error)
          })
    },

注意: 发布的WebAPI项目中有模板文件和文件夹

相关推荐
灵析表格2 小时前
灵析表格函数精讲|Json转表格_Pro:复杂嵌套与选型
json·excel·办公自动化·wps·效率工具·数据处理·ai办公
Warson_L6 小时前
.NET 8 速成笔记 16:API 框架到底怎么用,谁是自带的、谁是自己写的、配置和测试库如何关联
c#·.net
我命由我123457 小时前
Excel - Excel 固定列,滚动时该列始终可见
运维·学习·职场和发展·excel·职场发展·运维开发·学习方法
灵析表格7 小时前
灵析表格函数精讲|xml转json:供应商配置转换
xml·json·excel·办公自动化·wps·效率工具·ai办公
派大猩猩_7 小时前
同一份 Excel 多人修改如何避免覆盖?本地编辑与在线共编的冲突机制与恢复
excel·文件同步·网盘·在线编辑·多人在线编辑·excel协同
淡海水9 小时前
01-10-认知篇-对比-方案选型矩阵
矩阵·c#·excel·游戏开发·luban
reasonsummer12 小时前
【办公类-178-01】20261204医保需要“幼儿园园通学籍证明截图”(Python页面截图+转PDF)
开发语言·c#
yuzhiboyouye13 小时前
我做web前端八年多了,转C#怎么样,而且我现在的java是初级水平,问的通义
c#
小宋102113 小时前
知识库里的 Excel 不能当纯文本读:表头行识别、合并单元格回填与公式缓存值的结构化入库
前端·人工智能·缓存·excel
yuzhiboyouye14 小时前
我现在初级java,中高级web前端。那我C#的学习路径是?问的tare chat智能体
c#