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

相关推荐
hqyjzsb3 小时前
从爱好到专业:AI初学者如何跨越CAIE认证的理想与现实鸿沟
大数据·c语言·人工智能·信息可视化·职场和发展·excel·业界资讯
Macbethad5 小时前
区块链技术在分布式系统中的应用实践技术报告
开发语言·c#
玩泥巴的6 小时前
如何在.NET系统中快速集成飞书任务分配能力
c#·.net·二次开发·飞书
bugcome_com6 小时前
深入理解 C# 特性(Attribute):概念、实现与实战
c#·.net
WebRuntime7 小时前
所有64位WinForm应用都是Chromium浏览器(2)
javascript·c#·.net·web
Sunsets_Red8 小时前
待修改莫队与普通莫队优化
java·c++·python·学习·算法·数学建模·c#
vfvfb8 小时前
excel对比找不同人名 双xlsx双列对比
excel·excel多列对比
时光追逐者9 小时前
一款基于 .NET 9 构建的企业级 Web RBAC 快速开发框架
前端·c#·.net·.net core
想你依然心痛9 小时前
【TextIn大模型加速器+火山引擎】打造智能文档处理流水线:从跨国药企手册到金融单据核验的全链路实战
金融·c#·火山引擎
kingwebo'sZone9 小时前
win11智能应用控制已阻止此应用
c#