1.先安装
npm install --save xlsx
2.文件中引入
import * as XLSX from "xlsx";
3.点击事件
<templat> <el-button @click="excel"/> </templat> <script setup> import * as XLSX from "xlsx"; const excel = () =>{ dataa.value = XLSX.utils.json_to_sheet(daochu_quanbu.value);//此处daochu_quanbu.value为表格的数据 const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, dataa.value, ".docx"); //test-data为自定义的sheet表名 XLSX.writeFile(wb, nowDate(b) + "兑换码列表.docx"); //test.xlsx为自定义的文件名 } </script>