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

git官網vue

安裝:git

cnpm install --save xlsx file-saver

.vue文件中:
1. 引用table插件/本身寫table佈局 <el-table id="my-table"></el-table>
2. 引入依賴github

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

3. 下載功能使用:npm

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;
},

 

詳細整理該組件:app

相關文章
相關標籤/搜索