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

相关推荐
longxiaozhang63 小时前
C#继承:让代码少写一点,偷懒的好方法
开发语言·c#
rockey6274 小时前
C#脚本引擎之AScript与DynamicExpresso对比
c#·.net·script·动态脚本
AI导出鸭5 小时前
怎么让文心做表格?AI导出鸭苹果版将文心输出的管道表格智能解析为二维结构,一键导出为Excel或Word标准表格
人工智能·chatgpt·word·excel·ai导出鸭
admin00515 小时前
Excel记账和财务软件记账哪个好?效率与准确率真实对比
excel·excel记账·财务软件记账·小微企业记账
Vae_Mars16 小时前
C#中的delegate委托
开发语言·c#
公子小六20 小时前
基于.NET的Windows窗体编程之WinForms音频控件
windows·microsoft·c#·.net·音视频·winforms
绿浪198421 小时前
c# 结构体 能不能直接封送检测
开发语言·c#
新手unity自用笔记21 小时前
unity基于Socket的网络学习
网络·网络协议·学习·unity·c#·游戏引擎
Python私教1 天前
Excel 和群聊什么时候该升级成管理系统?7 个判断信号
excel·管理系统·权限设计
鲲穹AI种草1 天前
表格数据处理怎么选?多款 Excel 工具能力客观记录
excel·表格数据处理