forked from github/dataease
Merge pull request #9259 from dataease/pr@dev@refactor_report
refactor(X-Pack): 定时报告导出的excel可以识别数值类型 #8999
This commit is contained in:
commit
4dcf81c16e
@ -13,4 +13,6 @@ public class ExcelSheetModel {
|
||||
|
||||
private List<List<String>> data;
|
||||
|
||||
private List<Integer> filedTypes;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.commons.model.excel.ExcelSheetModel;
|
||||
import io.dataease.plugins.common.constants.DeTypeConstants;
|
||||
import io.dataease.plugins.common.util.FileUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -27,6 +28,7 @@ public class ExcelUtils {
|
||||
sheets.forEach(sheet -> {
|
||||
|
||||
List<List<String>> details = sheet.getData();
|
||||
List<Integer> fieldTypes = sheet.getFiledTypes();
|
||||
details.add(0, sheet.getHeads());
|
||||
String sheetName = sheet.getSheetName();
|
||||
Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]");
|
||||
@ -53,7 +55,12 @@ public class ExcelUtils {
|
||||
if (rowData != null) {
|
||||
for (int j = 0; j < rowData.size(); j++) {
|
||||
Cell cell = row.createCell(j);
|
||||
cell.setCellValue(rowData.get(j));
|
||||
// with DataType
|
||||
if (i > 0 && (fieldTypes.get(j).equals(DeTypeConstants.DE_INT) || fieldTypes.get(j).equals(DeTypeConstants.DE_FLOAT)) && StringUtils.isNotEmpty(rowData.get(j))) {
|
||||
cell.setCellValue(Double.valueOf(rowData.get(j)));
|
||||
} else {
|
||||
cell.setCellValue(rowData.get(j));
|
||||
}
|
||||
if (i == 0) {// 头部
|
||||
cell.setCellStyle(cellStyle);
|
||||
// 设置列的宽度
|
||||
|
@ -113,11 +113,13 @@ public class ViewExportExcel {
|
||||
List<ChartViewFieldDTO> fields = gson.fromJson(gson.toJson(objectFields), fieldTokenType);
|
||||
List<String> heads = new ArrayList<>();
|
||||
List<String> headKeys = new ArrayList<>();
|
||||
List<Integer> fieldTypes = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(fields)) {
|
||||
fields.forEach(field -> {
|
||||
if (ObjectUtils.isNotEmpty(field.getName()) && ObjectUtils.isNotEmpty(field.getDataeaseName())) {
|
||||
heads.add(field.getName());
|
||||
headKeys.add(field.getDataeaseName());
|
||||
fieldTypes.add(field.getDeType());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -132,6 +134,7 @@ public class ViewExportExcel {
|
||||
}).collect(Collectors.toList())).collect(Collectors.toList());
|
||||
result.setHeads(heads);
|
||||
result.setData(details);
|
||||
result.setFiledTypes(fieldTypes);
|
||||
|
||||
result.setSheetName(title);
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user