refactor(仪表板): 导出视图明细excel,数值类型按照原格式导出

This commit is contained in:
wangjiahao 2022-08-18 11:40:35 +08:00
parent aae72c991a
commit aebe98c68a
3 changed files with 19 additions and 2 deletions

View File

@ -16,6 +16,8 @@ public class PanelViewDetailsRequest {
private String[] header;
private Integer[] excelTypes;
private List<String[]> details;
private String snapshot;
@ -25,4 +27,5 @@ public class PanelViewDetailsRequest {
private int snapshotHeight;
}

View File

@ -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<String[]> 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]);
}
}
}
}

View File

@ -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