From aebe98c68aeafef67a4417597d0f2ecae970cbd1 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Thu, 18 Aug 2022 11:40:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=AA=E8=A1=A8=E6=9D=BF):=20?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E8=A7=86=E5=9B=BE=E6=98=8E=E7=BB=86excel,?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E6=8C=89=E7=85=A7=E5=8E=9F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/panel/PanelViewDetailsRequest.java | 3 +++ .../service/panel/PanelGroupService.java | 16 ++++++++++++++-- .../canvas/custom-component/UserViewDialog.vue | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/controller/request/panel/PanelViewDetailsRequest.java b/backend/src/main/java/io/dataease/controller/request/panel/PanelViewDetailsRequest.java index 44fba1de45..841ff36e8b 100644 --- a/backend/src/main/java/io/dataease/controller/request/panel/PanelViewDetailsRequest.java +++ b/backend/src/main/java/io/dataease/controller/request/panel/PanelViewDetailsRequest.java @@ -16,6 +16,8 @@ public class PanelViewDetailsRequest { private String[] header; + private Integer[] excelTypes; + private List details; private String snapshot; @@ -25,4 +27,5 @@ public class PanelViewDetailsRequest { private int snapshotHeight; + } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java index 91ceb1f0fa..4f5832dddf 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java @@ -8,7 +8,6 @@ import io.dataease.controller.request.authModel.VAuthModelRequest; import io.dataease.controller.request.dataset.DataSetTableRequest; import io.dataease.controller.request.panel.PanelGroupBaseInfoRequest; import io.dataease.controller.request.panel.PanelGroupRequest; -import io.dataease.controller.request.panel.PanelTemplateRequest; import io.dataease.controller.request.panel.PanelViewDetailsRequest; import io.dataease.dto.PanelGroupExtendDataDTO; import io.dataease.dto.SysLogDTO; @@ -24,6 +23,7 @@ import io.dataease.i18n.Translator; import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.base.domain.*; import io.dataease.plugins.common.base.mapper.*; +import io.dataease.plugins.common.constants.DeTypeConstants; import io.dataease.service.chart.ChartViewService; import io.dataease.service.dataset.DataSetTableService; import io.dataease.service.staticResource.StaticResourceService; @@ -549,6 +549,7 @@ public class PanelGroupService { try { String snapshot = request.getSnapshot(); List details = request.getDetails(); + Integer[] excelTypes = request.getExcelTypes(); details.add(0, request.getHeader()); HSSFWorkbook wb = new HSSFWorkbook(); //明细sheet @@ -575,11 +576,22 @@ public class PanelGroupService { if (rowData != null) { for (int j = 0; j < rowData.length; j++) { HSSFCell cell = row.createCell(j); - cell.setCellValue(rowData[j]); if (i == 0) {// 头部 + cell.setCellValue(rowData[j]); cell.setCellStyle(cellStyle); //设置列的宽度 detailsSheet.setColumnWidth(j, 255 * 20); + }else{ + // with DataType + if((excelTypes[j]== DeTypeConstants.DE_INT || excelTypes[j]== DeTypeConstants.DE_FLOAT)&& StringUtils.isNotEmpty(rowData[j])){ + try{ + cell.setCellValue(Double.valueOf(rowData[j])); + }catch (Exception e){ + LogUtil.warn("export excel data transform error"); + } + }else{ + cell.setCellValue(rowData[j]); + } } } } diff --git a/frontend/src/components/canvas/custom-component/UserViewDialog.vue b/frontend/src/components/canvas/custom-component/UserViewDialog.vue index 1f7b522301..5905c74d75 100644 --- a/frontend/src/components/canvas/custom-component/UserViewDialog.vue +++ b/frontend/src/components/canvas/custom-component/UserViewDialog.vue @@ -182,6 +182,7 @@ export default { }, exportExcelDownload(snapshot, width, height) { const excelHeader = JSON.parse(JSON.stringify(this.chart.data.fields)).map(item => item.name) + const excelTypes = JSON.parse(JSON.stringify(this.chart.data.fields)).map(item => item.deType) const excelHeaderKeys = JSON.parse(JSON.stringify(this.chart.data.fields)).map(item => item.dataeaseName) const excelData = JSON.parse(JSON.stringify(this.chart.data.tableRow)).map(item => excelHeaderKeys.map(i => item[i])) const excelName = this.chart.name @@ -189,6 +190,7 @@ export default { viewName: excelName, header: excelHeader, details: excelData, + excelTypes: excelTypes, snapshot: snapshot, snapshotWidth: width, snapshotHeight: height