vue+file-saver+xlsx匯出table為excel
阿新 • • 發佈:2018-11-12
1、安裝:npm install file-saver xlsx --save-dev
2、引入:import FileSaver from 'file-save';
import XLSX from 'xlsx';
3、點選事件:
exportExcel() {
let vb = XLSX.utils.table_to_book(document.getElementById('outTable'));
let vbout = XLSX.write(vb, {bookType: 'xlsx', bookSST: true, type: 'array'});
try {
FileSaver.saveAs(new Blob([vbout], {type: 'application/octet-stream'}), 'sheetjs.xlsx');
} catch (e) {
if (typeof console !== 'undefined') console.log(e, vbout);
}
return vbout;
}