In vue2.0 + element UI, the el-table data export Excel method is vue2.0el-table.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.