|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <el-button size="small" type="primary" @click="setExport2Excel">
|
|
|
+ <el-button :size="buttonSize" type="primary" @click="setExport2Excel">
|
|
|
导出
|
|
|
</el-button>
|
|
|
</template>
|
|
@@ -9,7 +9,28 @@
|
|
|
import XLSX2 from 'xlsx'
|
|
|
import XLSX from 'xlsx-style'
|
|
|
export default {
|
|
|
- props: ['tableId', 'file', 'clickfun'],
|
|
|
+ props: {
|
|
|
+ 'tableId': {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ 'file': {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ 'clickfun': {
|
|
|
+ type: Function,
|
|
|
+ default: () => {}
|
|
|
+ },
|
|
|
+ buttonSize: {
|
|
|
+ type: String,
|
|
|
+ default: 'small'
|
|
|
+ },
|
|
|
+ name: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
todayTimeString: new Date().getTime()
|
|
@@ -57,9 +78,11 @@ export default {
|
|
|
'电量': row => row.s.numFmt = '0%' // (row.v *= 100, )
|
|
|
}
|
|
|
var cacheCells = {}
|
|
|
+ // 循环处理数据
|
|
|
for (const key in wb) {
|
|
|
if (key.indexOf('!') > -1) continue
|
|
|
- if (['', '操作', '详情', '编辑详情'].indexOf(wb[key].v) > -1) {
|
|
|
+ const tempKey = key.replace(/\d+/g, '')
|
|
|
+ if (['操作', '详情', '编辑详情'].indexOf(wb[key].v) > -1 || !wb[tempKey + '1'].v) {
|
|
|
delete wb[key]
|
|
|
continue
|
|
|
} else {
|
|
@@ -88,7 +111,6 @@ export default {
|
|
|
right: { style: 'thin' }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (rowW == 1 && cells.hasOwnProperty(wb[key].v)) {
|
|
|
cacheCells[cellW] = cells[wb[key].v]
|
|
|
} else if (cacheCells.hasOwnProperty(cellW)) {
|
|
@@ -96,16 +118,17 @@ export default {
|
|
|
}
|
|
|
if (wb[key].z == 'm/d/yy') {
|
|
|
delete wb[key].z
|
|
|
- // wb[key].s.numFmt = 'yyyy-m-dd h:mm:ss'
|
|
|
wb[key].s.numFmt = 'yyyy-m-dd'
|
|
|
wb[key].v -= 0.0004976851
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 导出数据
|
|
|
var data = wb['!merges'] ? this.addRangeBorder(wb['!merges'], wb) : wb // 合并项添加边框
|
|
|
var filedata = this.sheet2blob(data)
|
|
|
- this.openDownloadDialog(filedata, this.todayTimeString + '-' + (this.file || '') + '报表.xlsx')
|
|
|
+ const name = this.name ? (this.todayTimeString + '-' + (this.name || '') + '.xlsx') : (this.todayTimeString + '-' + (this.file || '') + '报表.xlsx')
|
|
|
+ this.openDownloadDialog(filedata, name)
|
|
|
},
|
|
|
// 为合并项添加边框
|
|
|
addRangeBorder(range, ws) {
|