纯 js 导出 excel
生活随笔
收集整理的這篇文章主要介紹了
纯 js 导出 excel
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.npmjs.com/package/js-export-excel
第一步,先安裝該組件:
npm install js-export-exceloryarn add js-export-excel第二步,在需要地方引用
const ExportJsonExcel = require("js-export-excel");orimport ExportJsonExcel from "js-export-excel";開始使用
<template><div class="about"><button @click="exportExcel">點擊導出</button></div> </template> <script>import ExportJsonExcel from "js-export-excel"; export default {data(){return{selections:[{'index':'0',"num": "001", "name": "小明"},{'index':'1',"num": "002", "name": "小紅"},{'index':'2',"num": "003", "name": "小蘭"}]}},methods: {//定義導出Excel表格事件exportExcel: function () {var data = this.selections;//選中的數據let dataTable = [];if (data && data.length > 0) {for (let i in data) {if (data[i]) {let obj = {索引: data[i].index,學號: data[i].num,姓名: data[i].name};dataTable.push(obj);}}this.exportToExcel(dataTable);}},exportToExcel (dataTable) {var option = {};option.fileName = "學生信息";option.datas = [{sheetData: dataTable,sheetName: "sheet",sheetFilter: ["索引", // 要和上面定義的對應"學號","姓名"],sheetHeader: ["索引","學號","姓名"]}];var toExcel = new ExportJsonExcel(option);toExcel.saveExcel();}} } </script> <style scoped> </style>總結
以上是生活随笔為你收集整理的纯 js 导出 excel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 酷家乐瓷砖异形切割怎么做? 酷家乐异形切
- 下一篇: H5 获取手机GPS坐标