vue导出复杂excel表格
1、安装依赖
npm install file-saver --save
npm install xlsx --save
npm install xlsx-style --save
2、引入依赖
import FileSaver from 'file-saver';
import XLSX from 'xlsx';
import XLSXStyle from 'xlsx-style'
3、JS代码
exportExcel() {
let elt = document.getElementById('exportTable');
let wb = XLSX.utils.table_to_book(elt, {
sheet: 'Sheet JS', raw: true });
let range = XLSX.utils.decode_range(wb.Sheets['Sheet JS']['!ref']);
let borderStyle = {
top: {
style: 'thin',
color: {
rgb: '000000' }
},
bottom: {
style: 'thin',
color: {
rgb: '000000' }
},
left: {
style: 'thin',
color: {
rgb: '000000' }
},
right: {
style: 'thin',
color: {
rgb: