1、根据业务需要直接在wps规定Excel模板保存(文件名可以是中文或英文),如下:
2、直接复制excel文件到vue项目中,如下:
vue3.0版本的在项目public目录下新建static文件夹,放入“文件模板.xlsx”文件。
vue2.0版本的在项目根目录下的static文件夹,放入“文件模板.xlsx”文件。
3、下载模板
<template> <el-button type="primary" icon="download"@click="downloadTemplate">下载模板</el-button> </template><script setup> const downloadTemplate=() =>{ let a = document.createElement("a"); a.href = "./static/上传模板.xlsx"; //对应模板 // a.download = "上传模板.xlsx"; //如果文件名是英文,可以在这里修改下载的文件名 a.style.display = "none"; document.body.appendChild(a); a.click(); a.remove(); } </script>