抓住九月的尾巴分享一个插件XLSX

git官网

安装:

cnpm install --save xlsx file-saver

.vue文件中:
1. 引用table插件/自己写table布局 <el-table id="my-table"></el-table>
2. 引入依赖

import FileSaver from 'file-saver' 
import XLSX from 'xlsx'

3. 下载功能使用:

exportExcel () {
  /* 从表中生成工作簿对象 */
  var wb = XLSX.utils.table_to_book(document.querySelector('#my-table'))
    /* 获取二进制字符串作为输出 */
    var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
    try {
        /* 存储到本地 */
        FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }),     'sheetjs.xlsx')
    } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
    return wbout;
},

详细整理该组件:

猜你喜欢

转载自www.cnblogs.com/padding1015/p/11613751.html