|
|
@ -9,17 +9,25 @@ export function exportExcel(columnList = [], listData = [], name = 'excel') { |
|
|
|
|
|
|
|
|
|
|
|
const blackArr = ['序号', '复选框', '操作', '全选']; |
|
|
|
const blackArr = ['序号', '复选框', '操作', '全选']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _columnData = columnList.filter(item => !blackArr.includes(item.label)); |
|
|
|
|
|
|
|
|
|
|
|
const data = []; |
|
|
|
const data = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const marginList = []; |
|
|
|
|
|
|
|
|
|
|
|
for (let j = 0; j < listData.length; j++) { |
|
|
|
for (let j = 0; j < listData.length; j++) { |
|
|
|
const item = listData[j]; |
|
|
|
const item = listData[j]; |
|
|
|
const arr = []; |
|
|
|
const arr = []; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < columnList.length; i++) { |
|
|
|
for (let i = 0; i < _columnData.length; i++) { |
|
|
|
const val = columnList[i]; |
|
|
|
const val = _columnData[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (blackArr.includes(val.label) || val.head) continue; |
|
|
|
if (blackArr.includes(val.label) || val.head) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (val.isColumnMerge && isNumber(item.mergeColumnIndex) && item.mergeColumnIndex > 1) { |
|
|
|
|
|
|
|
marginList.push({ s: { r: j, c: i }, e: { r: j + item.mergeColumnIndex, c: i } }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (j === 0) headers.push(val.label); |
|
|
|
if (j === 0) headers.push(val.label); |
|
|
|
arr.push(item[val.prop] || item[val.prop] === 0 ? item[val.prop] : ''); |
|
|
|
arr.push(item[val.prop] || item[val.prop] === 0 ? item[val.prop] : ''); |
|
|
|
} |
|
|
|
} |
|
|
@ -56,7 +64,7 @@ export function exportExcel(columnList = [], listData = [], name = 'excel') { |
|
|
|
let valueWidth = 0; |
|
|
|
let valueWidth = 0; |
|
|
|
if (value) |
|
|
|
if (value) |
|
|
|
if (/.*[\u4e00-\u9fa5]+.*$/.test(value)) { |
|
|
|
if (/.*[\u4e00-\u9fa5]+.*$/.test(value)) { |
|
|
|
valueWidth = parseFloat(value.trim().toString().length * 2.1) + 4; |
|
|
|
valueWidth = parseFloat(value.trim().toString().length * 1.5) + 4; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
valueWidth = parseFloat(value.toString().length * 1.1) + 4; |
|
|
|
valueWidth = parseFloat(value.toString().length * 1.1) + 4; |
|
|
|
} |
|
|
|
} |
|
|
@ -75,9 +83,9 @@ export function exportExcel(columnList = [], listData = [], name = 'excel') { |
|
|
|
|
|
|
|
|
|
|
|
// 3.对比每列最大值
|
|
|
|
// 3.对比每列最大值
|
|
|
|
let aotuWidth = []; |
|
|
|
let aotuWidth = []; |
|
|
|
rowsWidth.map((row, index) => { |
|
|
|
rowsWidth.forEach((row, index) => { |
|
|
|
let maxWidth = []; |
|
|
|
let maxWidth = []; |
|
|
|
row.map((value, i) => { |
|
|
|
row.forEach((value, i) => { |
|
|
|
if (index === 0) { |
|
|
|
if (index === 0) { |
|
|
|
maxWidth.push({ |
|
|
|
maxWidth.push({ |
|
|
|
wch: value, |
|
|
|
wch: value, |
|
|
@ -94,6 +102,7 @@ export function exportExcel(columnList = [], listData = [], name = 'excel') { |
|
|
|
|
|
|
|
|
|
|
|
// 4.给excel设置自适应宽度
|
|
|
|
// 4.给excel设置自适应宽度
|
|
|
|
ws['!cols'] = aotuWidth; |
|
|
|
ws['!cols'] = aotuWidth; |
|
|
|
|
|
|
|
ws['!merges'] = marginList; |
|
|
|
const excludes = ['!cols', '!fullref', '!merges', '!ref', '!rows']; |
|
|
|
const excludes = ['!cols', '!fullref', '!merges', '!ref', '!rows']; |
|
|
|
console.log('ws :>> ', ws); |
|
|
|
console.log('ws :>> ', ws); |
|
|
|
for (let key in ws) { |
|
|
|
for (let key in ws) { |
|
|
@ -102,7 +111,7 @@ export function exportExcel(columnList = [], listData = [], name = 'excel') { |
|
|
|
ws[key].s = { |
|
|
|
ws[key].s = { |
|
|
|
alignment: { |
|
|
|
alignment: { |
|
|
|
// horizontal: 'center', //水平居中对齐
|
|
|
|
// horizontal: 'center', //水平居中对齐
|
|
|
|
// vertical: 'center', // 垂直居中
|
|
|
|
vertical: 'center', // 垂直居中
|
|
|
|
wrapText: true, |
|
|
|
wrapText: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
border: { |
|
|
|
border: { |
|
|
|