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

相关推荐
hixiong12314 分钟前
C# 使用 ZXingCpp.Angle 进行条码、二维码识别
开发语言·c#·扫码
步步为营DotNet39 分钟前
System.Text.Json 源生成:三个“看起来已经生效“的静默失效
c#·.net·native aot·源生成
reasonsummer10 小时前
【办公类-53-12】20261016(预测)Python模仿制作2026学年第二学期校历(excel+pdf,上下学期都包含)
pdf·excel
泡海椒14 小时前
JQuick-Excel 自定义 SPI Provider:用 fullName 扩展 TRANSFORM 函数
驱动开发·excel
用户7884773163415 小时前
用 C# 把每周 6 小时的 PDF 录入干到 20 分钟:一份可复制的桌面 OCR 方案
c#
csdn_aspnet17 小时前
C# .NetCore Swagger ISchemaFilter 处理枚举、特殊类型
c#·.netcore·swagger
滴滴答答哒17 小时前
C# 技巧:优雅实现对象的“局部更新”与“字段合并”
开发语言·c#
泡海椒18 小时前
从 XML 到 Excel:JQuick-Excel 代理与解析器如何协作
xml·excel
code_long1 天前
.net core 连接打印机 使用zpl指令打印机,并且位图本地渲染zpl指令
c#·.netcore·位图·打印机·模板编辑·模板预览
优选资讯1 天前
Excel 批量打印标签的完整流程
excel