In vue2.0 + element UI, the el-table data export Excel method is vue2.0el-table.
1. Install related dependencies
There are two main dependencies.
npm install --save xlsx file-saver
If you want to see the use of the two plug-ins in detail, please go to github.
Https://github.com/SheetJS/js-xlsx
Https://github.com/eligrey/FileSaver.js
2. Introduced in components
import FileSaver from 'file-saver'import XLSX from 'xlsx'
3. Write a method in the component methods.
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},
Note: XLSX. uitls. table_to_book (where the DOM node of the table is placed). sheetjs.xlsx is the name of the exported table. You can modify it!
4. Click the export button to execute the exportExcel method.
Code in the component:
The implementation is as follows:
Export the data in the following table to excel.
Export to an excel file. The result is as follows:
Related links:
Other Use Cases of this tool (such as react, jQ, angular) http://sheetjs.com/
In the preceding vue2.0 + element UI, the el-table data export Excel method is all the content that I have shared with you. I hope to give you a reference and support for more.