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

相关推荐
用户298698530148 小时前
在 PC 上将 HTML 转换为 PDF 的3种有效方法
人工智能·c#·html
ms365copilot10 小时前
Excel 新模型Claude Opus 5
人工智能·excel
Rotion_深10 小时前
C# 设计TCP Server
开发语言·tcp/ip·c#
csdn_aspnet11 小时前
C# 从凸包中删除点(Deleting points from Convex Hull)
开发语言·c#
蓝创工坊Blue Foundry12 小时前
发票、凭证和对账单怎么整理成 Excel?先定义字段,再逐项复核
pdf·ocr·excel·文心一言·paddlepaddle
czhc114007566312 小时前
7.28 从“图形状态切换“理解 Parse 与状态驱动模式
c#
ms365copilot13 小时前
Copilot直接读取Excel,一键生成完整数据汇报PPT
powerpoint·excel·copilot
逻极14 小时前
C# 从入门到精通:现代云原生与AI应用开发实战
ai·云原生·c#·.net
geovindu1 天前
CSharp: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·算法·c#·.net·搜索算法
石马马户1 天前
excel中使用宏绘制折线图
excel