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

相关推荐
灵析表格1 小时前
灵析表格函数精讲|AI_NLP_提取重点关键词:抓商品标题核心词
excel·办公自动化·wps·效率工具·数据处理·ai办公·函数公式
ComPDFKit6 小时前
扫描对账单 PDF 转 Excel,怎么查出金额错行?
python·pdf·excel
看浪的路人7 小时前
第10讲:运维 Agent——从「被动救火」到「自动驾驶」
c#·linq
Logic1018 小时前
Excel定义名称4:省市县三级联动菜单
excel·indirect·excel函数·定义名称·联动菜单·数据有效性·省市县联动菜单
SunnyDays10119 小时前
Java 填充 Excel 模板:用命名区域告别写死的单元格地址
java·excel
Jazz_z10 小时前
C# 实现 Word 文档内容复制
开发语言·c#·word
淡海水14 小时前
02-02-原理篇-Scriban模板引擎原理深度解析
unity·excel·游戏开发·luban
优选资讯1 天前
合格证套打怎么落地:Luck标签软件把 Excel 字段、编号和打印预览一次做顺
excel·标签打印·luck标签软件
Logic1011 天前
Excel定义名称2,跨表汇总求最值
excel·indirect·sumif·excel函数·定义名称·跨表查询
Matt Feng1 天前
PDF表格转Excel:合并单元格和列宽的5个设置
pdf·excel·wps