From d0bdec5e769520fcb7e40af72e8f13f1382fcdd1 Mon Sep 17 00:00:00 2001 From: wisonic-s <51065359+wisonic-s@users.noreply.github.com> Date: Thu, 19 Jun 2025 16:25:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E9=80=8F=E8=A7=86?= =?UTF-8?q?=E8=A1=A8=E5=B8=A6=E6=A0=BC=E5=BC=8F=E5=AF=BC=E5=87=BA=E5=8F=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/common/common_table.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts index 5516d1591c..2fddd3f9c9 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts @@ -1377,9 +1377,9 @@ export async function exportGridPivot(instance: PivotSheet, chart: ChartObj) { if (fieldValue === 0 || fieldValue) { const meta = metaMap[dataCellMeta.valueField] const cell = worksheet.getCell(rowIndex + maxColHeight + 1, rowLength + colIndex + 1) - const value = meta?.formatter?.(fieldValue) || fieldValue.toString() + const value = meta?.formatter?.(fieldValue) || fieldValue cell.alignment = { vertical: 'middle', horizontal: 'center' } - cell.value = value + cell.value = isNumeric(value) ? parseFloat(value) : value } } } @@ -1548,9 +1548,9 @@ export async function exportRowQuotaGridPivot(instance: PivotSheet, chart: Chart if (fieldValue === 0 || fieldValue) { const meta = metaMap[dataCellMeta.valueField] const cell = worksheet.getCell(rowIndex + maxColHeight + 1, rowLength + colIndex + 2) - const value = meta?.formatter?.(fieldValue) || fieldValue.toString() + const value = meta?.formatter?.(fieldValue) || fieldValue cell.alignment = { vertical: 'middle', horizontal: 'center' } - cell.value = value + cell.value = isNumeric(value) ? parseFloat(value) : value } } } @@ -1670,9 +1670,9 @@ export async function exportTreePivot(instance: PivotSheet, chart: ChartObj) { if (fieldValue === 0 || fieldValue) { const meta = metaMap[dataCellMeta.valueField] const cell = worksheet.getCell(rowIndex + maxColHeight + 1, colIndex + 1 + 1) - const value = meta?.formatter?.(fieldValue) || fieldValue.toString() + const value = meta?.formatter?.(fieldValue) || fieldValue cell.alignment = { vertical: 'middle', horizontal: 'center' } - cell.value = value + cell.value = isNumeric(value) ? parseFloat(value) : value } } } @@ -1793,9 +1793,9 @@ export async function exportRowQuotaTreePivot(instance: PivotSheet, chart: Chart if (fieldValue === 0 || fieldValue) { const meta = metaMap[dataCellMeta.valueField] const cell = worksheet.getCell(rowIndex + maxColHeight + 1, colIndex + 2) - const value = meta?.formatter?.(fieldValue) || fieldValue.toString() + const value = meta?.formatter?.(fieldValue) || fieldValue cell.alignment = { vertical: 'middle', horizontal: 'center' } - cell.value = value + cell.value = isNumeric(value) ? parseFloat(value) : value } } } @@ -1806,6 +1806,11 @@ export async function exportRowQuotaTreePivot(instance: PivotSheet, chart: Chart saveAs(dataBlob, `${chart.title ?? '透视表'}.xlsx`) } + +function isNumeric(value: string): boolean { + return /^[+-]?\d+(\.\d+)?$/.test(value) +} + export async function exportPivotExcel(instance: PivotSheet, chart: ChartObj) { const { fields } = instance.dataCfg const rowLength = fields?.rows?.length || 0