vue前端导出excel

发布时间 2023-03-23 11:23:09作者: 212的s
<template>
  
 <el-button style="float: right; margin: 10px" type="primary" @click="export2">导出</el-button>

  

   <!-- 导出表格 start--> <el-table class="tableExport" :data="tableData" hidden> </el-table> <!-- 导出表格 end--> </template> <script>
//"xlsx": "^0.18.5",
//"file-saver": "^2.0.5",

  

import FileSaver from 'file-saver'
var XLSX = require('xlsx')




 methods: {
      export2() {
        //  .table要导出的是哪一个表格
        var excelDom = XLSX.utils.table_to_book(document.querySelector('.tableExport'))
        var excelType = XLSX.write(excelDom, {
          bookType: 'xlsx',
          bookSST: true,
          type: 'array',
        })
        try {
          //  name+'.xlsx'表示导出的excel表格名字
          FileSaver.saveAs(new Blob([excelType], { type: 'application/octet-stream' }), '产品数据表格.xlsx')
        } catch (e) {
          if (typeof console !== 'undefined');
        }
        return excelType
      },

</script>

//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿