From 16f6fdd8a12f07b0fadede4dea06d2933bd11bc8 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 17 Feb 2025 17:17:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA=20excel=20bug=20#14946?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/chart/server/ChartDataServer.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/chart/server/ChartDataServer.java b/core/core-backend/src/main/java/io/dataease/chart/server/ChartDataServer.java index 7f0454464f..f3a26ab3bd 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/server/ChartDataServer.java +++ b/core/core-backend/src/main/java/io/dataease/chart/server/ChartDataServer.java @@ -319,8 +319,7 @@ public class ChartDataServer implements ChartDataApi { if (viewInfo.getType().equalsIgnoreCase("table-normal") || viewInfo.getType().equalsIgnoreCase("table-info")) { for (ChartViewFieldDTO xAxi : xAxis) { if (xAxi.getDeType().equals(DeTypeConstants.DE_INT) || xAxi.getDeType().equals(DeTypeConstants.DE_FLOAT)) { - FormatterCfgDTO formatterCfgDTO = xAxi.getFormatterCfg() == null ? new FormatterCfgDTO() : xAxi.getFormatterCfg(); - CellStyle formatterCellStyle = createCellStyle(wb, formatterCfgDTO, null); + CellStyle formatterCellStyle = createCellStyle(wb, xAxi.getFormatterCfg(), null); styles.add(formatterCellStyle); } else { styles.add(null); @@ -416,13 +415,7 @@ public class ChartDataServer implements ChartDataApi { if ((viewInfo.getType().equalsIgnoreCase("table-normal") || viewInfo.getType().equalsIgnoreCase("table-info")) && (xAxis.get(j).getDeType().equals(DeTypeConstants.DE_INT) || xAxis.get(j).getDeType().equals(DeTypeConstants.DE_FLOAT))) { try { FormatterCfgDTO formatterCfgDTO = xAxis.get(j).getFormatterCfg() == null ? new FormatterCfgDTO() : xAxis.get(j).getFormatterCfg(); - if (formatterCfgDTO.getType().equalsIgnoreCase("auto")) { - row.getCell(j).setCellStyle(createCellStyle(wb, formatterCfgDTO, cellValue(formatterCfgDTO, new BigDecimal(cellValObj.toString())))); - } - if (styles.get(j) != null) { - row.getCell(j).setCellStyle(styles.get(j)); - } - + row.getCell(j).setCellStyle(styles.get(j)); row.getCell(j).setCellValue(Double.valueOf(cellValue(formatterCfgDTO, new BigDecimal(cellValObj.toString())))); } catch (Exception e) { cell.setCellValue(cellValObj.toString()); @@ -469,6 +462,11 @@ public class ChartDataServer implements ChartDataApi { private static CellStyle createCellStyle(Workbook workbook, FormatterCfgDTO formatter, String value) { CellStyle cellStyle = workbook.createCellStyle(); DataFormat format = workbook.createDataFormat(); + + if (formatter == null) { + cellStyle.setDataFormat(format.getFormat("General")); + return cellStyle; + } String formatStr = ""; if (formatter.getType().equals("auto")) { String[] valueSplit = String.valueOf(value).split(".");