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

相关推荐
杂货铺的小掌柜23 分钟前
apache poi excel 字体数量限制
java·excel·poi
云草桑2 小时前
.net AI MCP 入门 适用于模型上下文协议的 C# SDK 简介(MCP)
ai·c#·.net·mcp
工程师0074 小时前
C#中堆和栈的概念
c#·堆和栈
weixin_307779134 小时前
C#实现MySQL→Clickhouse建表语句转换工具
开发语言·数据库·算法·c#·自动化
CsharpDev-奶豆哥11 小时前
ASP.NET中for和foreach使用指南
windows·microsoft·c#·asp.net·.net
东方佑13 小时前
基于FastAPI与LangChain的Excel智能数据分析API开发实践
langchain·excel·fastapi
许泽宇的技术分享13 小时前
当Excel遇上大语言模型:ExcelAgentTemplate架构深度剖析与实战指南
语言模型·架构·excel
gihigo199814 小时前
基于MATLAB的Excel文件批量读取与循环处理
matlab·excel
cimeo15 小时前
【C 学习】12.2-函数补充
学习·c#
晚枫~18 小时前
零基础快速上手Playwright自动化测试
javascript·python·测试工具·c#·自动化