Home > Web Front-end > JS Tutorial > body text

How to export Excel from element UI

php中世界最好的语言
Release: 2018-04-12 14:28:08
Original
6643 people have browsed it

This time I will show you how to export Excel from element UI. What are the precautions when exporting Excel from element UI? Here is a practical case, let’s take a look.

1. Install related dependencies

Mainly two dependencies

npm install --save xlsx file-saver
Copy after login

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. Introduce

import FileSaver from 'file-saver'
import XLSX from 'xlsx'
Copy after login

into the component 3. Write a method in 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
},
Copy after login

Note: XLSX.uitls.table_to_book (the DOM node of the table is placed), sheetjs.xlsx is the name of the exported table, which can be modified!

4. Click the export button to execute the exportExcel method.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

##detailed explanation of the steps of vue-dplayer to implement hls playback

How does vue slot display the parent component in the child component and pass it

The above is the detailed content of How to export Excel from element UI. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!