1
0
mirror of synced 2025-11-06 04:10:39 +08:00

优化导出

This commit is contained in:
xuliangzhan
2023-07-07 08:24:45 +08:00
parent 7f97523626
commit 05c3679309
3 changed files with 15 additions and 11 deletions

View File

@@ -7,6 +7,10 @@
基于 [vxe-table](https://www.npmjs.com/package/vxe-table) 的表格插件,支持导出 xlsx 格式,基于 [exceljs](https://github.com/exceljs/exceljs) 实现
## Compatibility
对应 vxe-table v4 版本
## Installing
```shell

View File

@@ -128,8 +128,8 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
let beforeRowCount = 0
const colHead: any = {}
columns.forEach((column) => {
const { id, field, renderWidth } = column
colHead[id] = original ? field : column.getTitle()
const { id, field, renderWidth, headerExportMethod } = column as any
colHead[id] = headerExportMethod ? headerExportMethod({ column, $table }) : (original ? field : column.getTitle())
sheetCols.push({
key: id,
width: XEUtils.ceil(renderWidth / 8, 1)
@@ -138,17 +138,17 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
// 处理表头
if (isHeader) {
// 处理分组
if (isColgroup && !original && colgroups) {
if (isColgroup && colgroups) {
colgroups.forEach((cols, rIndex) => {
const groupHead: any = {}
columns.forEach((column) => {
groupHead[column.id] = null
})
cols.forEach((column) => {
const { _colSpan, _rowSpan } = column
const { _colSpan, _rowSpan, headerExportMethod } = column as any
const validColumn = getValidColumn(column)
const columnIndex = columns.indexOf(validColumn)
groupHead[validColumn.id] = original ? validColumn.field : column.getTitle()
groupHead[validColumn.id] = headerExportMethod ? headerExportMethod({ column, $table }) : (original ? validColumn.field : column.getTitle())
if (_colSpan > 1 || _rowSpan > 1) {
sheetMerges.push({
s: { r: rIndex, c: columnIndex },
@@ -164,7 +164,7 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
beforeRowCount += colList.length
}
// 处理合并
if (isMerge && !original) {
if (isMerge) {
mergeCells.forEach(mergeItem => {
const { row: mergeRowIndex, rowspan: mergeRowspan, col: mergeColIndex, colspan: mergeColspan } = mergeItem
sheetMerges.push({
@@ -187,7 +187,7 @@ function exportXLSX (params: VxeGlobalInterceptorHandles.InterceptorExportParams
const footers = getFooterData(options, footerData)
const mergeFooterItems = $table.getMergeFooterItems()
// 处理合并
if (isMerge && !original) {
if (isMerge) {
mergeFooterItems.forEach(mergeItem => {
const { row: mergeRowIndex, rowspan: mergeRowspan, col: mergeColIndex, colspan: mergeColspan } = mergeItem
sheetMerges.push({

View File

@@ -1,6 +1,6 @@
{
"name": "vxe-table-plugin-export-xlsx",
"version": "3.0.4",
"version": "3.0.5",
"description": "基于 vxe-table 的表格插件,支持导出 xlsx 格式",
"scripts": {
"lib": "gulp build"
@@ -49,9 +49,9 @@
"prettier": "^2.1.2",
"sass": "^1.55.0",
"typescript": "^4.6.4",
"vue": "^3.2.39",
"vxe-table": "^4.3.5",
"xe-utils": "^3.5.6"
"vue": "^3.3.4",
"vxe-table": "^4.4.5",
"xe-utils": "^3.5.11"
},
"peerDependencies": {
"vxe-table": "^4.0.27"