vue(excel导出)

//npm install --save xlsx file-saver

//需要调用的组件

import FileSaver from 'file-saver'

import XLSX from 'xlsx'

//导出方法,sheetjs.xlsx为文件名可更改,out-table为导出table id

exportExcel () { /* generate workbook object from table */

var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))

/* get binary string as output */

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

猜你喜欢

转载自blog.csdn.net/qq_39237755/article/details/80938785