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项目中有模板文件和文件夹

相关推荐
蒋胜山1 小时前
Excel 练习题(6)
经验分享·excel
唐青枫2 小时前
内存为什么越来越高?C#.NET GC 详解:分代回收、LOH、终结器与性能优化实战
c#·.net
xiaohe072 小时前
C#数据库操作系列---SqlSugar完结篇
网络·数据库·c#
wcy_10113 小时前
QCoder智能生成Excel数据清洗与可视化代码
python·excel
yngsqq15 小时前
平面图环 内轮廓
c#
rockey62717 小时前
AScript之eval函数详解
c#·.net·script·eval·expression·动态脚本
JoshRen21 小时前
2026教程:上传Excel,用Gemini 3镜像站多模态一键生成问卷分析图表代码与结论(附国内免费方案)
excel
He少年21 小时前
【AI 辅助案例分享】
人工智能·c#·编辑器·ai编程
工程师0071 天前
栈和堆的概念
c#·栈和堆
不会编程的懒洋洋1 天前
C# P/Invoke 基础
开发语言·c++·笔记·安全·机器学习·c#·p/invoke