Commit 648ba81e by xue_wengang

htmlToExcel

parent 79f52047
import FileSaver from 'file-saver';
import XLSX from 'xlsx';
export default {
// 导出Excel表格
exportExcel (name, tableName) {
debugger
//name表示生成excel的文件名 tableName表示表格的id
let fix = document.querySelector('.el-table__fixed');
//let con = document.querySelector(tableName);
//console.log(con);
let sel;
if(fix){ //判断要导出的节点中是否有fixed的表格,如果有,转换excel时先将该dom移除,然后append回去
sel = XLSX.utils.table_to_book(document.querySelector('#myTable').removeChild(fix));
document.querySelector('#myTable').appendChild(fix);
}else{
sel = XLSX.utils.table_to_book(document.querySelector(tableName));
}
//var sel = XLSX.utils.table_to_book(document.querySelector(tableName))
var selIn = XLSX.write(sel, { bookType: 'xlsx', bookSST: true, type: 'array' })
try {
FileSaver.saveAs(new Blob([selIn], { type: 'application/octet-stream' }), name)
} catch (e) {
if (typeof console !== 'undefined') console.log(e, selIn)
}
return selIn
}
};
...@@ -21,6 +21,8 @@ import moment from 'moment' ...@@ -21,6 +21,8 @@ import moment from 'moment'
import rules from "./utils/rules.js"; import rules from "./utils/rules.js";
import baseUrl from './api/base' import baseUrl from './api/base'
const Base64 = require('js-base64').Base64 const Base64 = require('js-base64').Base64
import htmlToExcel from './excel/htmlToExcel';
Vue.prototype.htmlToExcels = htmlToExcel;
//引入echarts //引入echarts
import echarts from 'echarts' import echarts from 'echarts'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment