|
@@ -159,19 +159,28 @@ export default {
|
|
exportTable (dom, title) {
|
|
exportTable (dom, title) {
|
|
const zim = 'A、B、C、D、E、F、G、H、I、J、K、L、M、N、O、P、Q、R、S、T、U、V、W、X、Y、Z'.split('、')
|
|
const zim = 'A、B、C、D、E、F、G、H、I、J、K、L、M、N、O、P、Q、R、S、T、U、V、W、X、Y、Z'.split('、')
|
|
var ws = XLSX.utils.table_to_sheet(dom)
|
|
var ws = XLSX.utils.table_to_sheet(dom)
|
|
- var wb = XLSX.utils.book_new()
|
|
|
|
// console.log(ws)
|
|
// console.log(ws)
|
|
// 设置样式
|
|
// 设置样式
|
|
Object.keys(ws).forEach(cell => {
|
|
Object.keys(ws).forEach(cell => {
|
|
if (cell[0] !== '!') {
|
|
if (cell[0] !== '!') {
|
|
- ws[cell].s = {
|
|
|
|
- alignment: {
|
|
|
|
- horizontal: 'center',
|
|
|
|
- vertical: 'center'
|
|
|
|
|
|
+ // 设置表头样式
|
|
|
|
+ if (cell === 'A1') {
|
|
|
|
+ ws[cell].s = {
|
|
|
|
+ font: { bold: true, color: { rgb: 'FFFFFF' } },
|
|
|
|
+ fill: { fgColor: { rgb: '4472C4' } },
|
|
|
|
+ alignment: { horizontal: 'center' }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ws[cell].s = {
|
|
|
|
+ alignment: {
|
|
|
|
+ horizontal: 'center',
|
|
|
|
+ vertical: 'center'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+
|
|
// 表格0
|
|
// 表格0
|
|
if (this.activeKey == 0) {
|
|
if (this.activeKey == 0) {
|
|
const ri = [6, 11, 20, 23]
|
|
const ri = [6, 11, 20, 23]
|
|
@@ -181,7 +190,8 @@ export default {
|
|
ri.forEach((row, j) => {
|
|
ri.forEach((row, j) => {
|
|
const a = ws[cols + row]
|
|
const a = ws[cols + row]
|
|
if (a) {
|
|
if (a) {
|
|
- a.z = (a.v * 100) + '%' // 设置单元格格式为百分比
|
|
|
|
|
|
+ a.v = Number(a.v * 100).toFixed(2) + '%' // 设置单元格格式为百分比
|
|
|
|
+ a.t = 's'
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -192,8 +202,10 @@ export default {
|
|
const cols = zim[this.columns.length - 1]
|
|
const cols = zim[this.columns.length - 1]
|
|
Array(this.totalNums).fill().forEach((item, i) => {
|
|
Array(this.totalNums).fill().forEach((item, i) => {
|
|
const a = ws[cols + (i + 3)]
|
|
const a = ws[cols + (i + 3)]
|
|
|
|
+ console.log(a)
|
|
if (a) {
|
|
if (a) {
|
|
- a.z = (a.v * 100) + '%' // 设置单元格格式为百分比
|
|
|
|
|
|
+ a.v = Number(a.v * 100).toFixed(2) + '%' // 设置单元格格式为百分比
|
|
|
|
+ a.t = 's'
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -205,7 +217,8 @@ export default {
|
|
Array(this.totalNums).fill().forEach((item, i) => {
|
|
Array(this.totalNums).fill().forEach((item, i) => {
|
|
const a = ws[cols + (i + 4)]
|
|
const a = ws[cols + (i + 4)]
|
|
if (a) {
|
|
if (a) {
|
|
- a.z = (a.v * 100) + '%' // 设置单元格格式为百分比
|
|
|
|
|
|
+ a.v = Number(a.v * 100).toFixed(2) + '%' // 设置单元格格式为百分比
|
|
|
|
+ a.t = 's'
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|
|
@@ -213,6 +226,8 @@ export default {
|
|
// 4. 设置列宽
|
|
// 4. 设置列宽
|
|
ws['!cols'] = Array(this.columns.length).fill().map(() => ({ wch: this.activeKey == 3 ? 15 : 35 }))
|
|
ws['!cols'] = Array(this.columns.length).fill().map(() => ({ wch: this.activeKey == 3 ? 15 : 35 }))
|
|
const timeStr = moment().format('YYYYMMDDHHmmss')
|
|
const timeStr = moment().format('YYYYMMDDHHmmss')
|
|
|
|
+ // 创建工作簿并导出
|
|
|
|
+ var wb = XLSX.utils.book_new()
|
|
// 5. 写入文件
|
|
// 5. 写入文件
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
|
|
XLSX.writeFile(wb, this.queryParam.month.split('-')[1] + '月' + title + '-' + timeStr + '.xlsx')
|
|
XLSX.writeFile(wb, this.queryParam.month.split('-')[1] + '月' + title + '-' + timeStr + '.xlsx')
|