|
|
@@ -29,24 +29,20 @@ import com.usoftchina.bi.server.service.chart.ChartsUtilService;
|
|
|
import com.usoftchina.bi.core.utils.GetTokenDataUtil;
|
|
|
import com.usoftchina.bi.server.service.common.MessageLogService;
|
|
|
import com.usoftchina.bi.server.service.dataSource.DataConnectorService;
|
|
|
-import org.apache.poi.hssf.usermodel.*;
|
|
|
-import org.apache.poi.hssf.util.HSSFCellUtil;
|
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
-import org.apache.poi.ss.format.CellFormatType;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@@ -441,8 +437,8 @@ public class DashboardsService {
|
|
|
* @param dashboardExportInfo
|
|
|
* @return
|
|
|
*/
|
|
|
- public HSSFWorkbook export(DashboardExportInfo dashboardExportInfo){
|
|
|
- HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ public XSSFWorkbook export(DashboardExportInfo dashboardExportInfo){
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
int dashboardId = dashboardExportInfo.getDashboardId();
|
|
|
List<DataSourceExportInfo> dataSourceExportInfoList = dashboardExportInfo.getData();
|
|
|
for (DataSourceExportInfo dataInfo : dataSourceExportInfoList) {
|
|
|
@@ -463,17 +459,17 @@ public class DashboardsService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void createExcelSheet(HSSFWorkbook workbook, String sheetName, List<Map<String, Object>> dataList, List<ColumnRenameInfo> columnRenameInfo) {
|
|
|
+ private void createExcelSheet(XSSFWorkbook workbook, String sheetName, List<Map<String, Object>> dataList, List<ColumnRenameInfo> columnRenameInfo) {
|
|
|
//添加sheet
|
|
|
- HSSFSheet sheet = workbook.createSheet(sheetName);
|
|
|
- HSSFRow row = sheet.createRow(0);
|
|
|
- HSSFCell cell;
|
|
|
- HSSFCellStyle cellStyle = getCellStyle(workbook);
|
|
|
+ XSSFSheet sheet = workbook.createSheet(sheetName);
|
|
|
+ XSSFRow row = sheet.createRow(0);
|
|
|
+ XSSFCell cell;
|
|
|
+ XSSFCellStyle cellStyle = getCellStyle(workbook);
|
|
|
//设置标题
|
|
|
for (int i = 0, len = columnRenameInfo.size(); i < len; i++) {
|
|
|
cell = row.createCell(i);
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
- cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
cell.setCellValue(columnRenameInfo.get(i).getColumnLable());
|
|
|
}
|
|
|
//设置数据
|
|
|
@@ -482,10 +478,10 @@ public class DashboardsService {
|
|
|
Map<String, Object> data = dataList.get(i);
|
|
|
for (int j = 0, size = columnRenameInfo.size(); j < size; j++) {
|
|
|
cell = row.createCell(j);
|
|
|
- int dataType = convertToCellType(columnRenameInfo.get(j).getColumnType());
|
|
|
+ CellType dataType = convertToCellType(columnRenameInfo.get(j).getColumnType());
|
|
|
Object value = data.get(columnRenameInfo.get(j).getColumnName());
|
|
|
- if (9 == dataType) {
|
|
|
- cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
|
|
|
+ if (CellType.BLANK.equals(dataType)) {
|
|
|
+ cell.setCellType(CellType.NUMERIC);
|
|
|
Date dataValue = null;
|
|
|
try {
|
|
|
dataValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(String.valueOf(value));
|
|
|
@@ -502,36 +498,36 @@ public class DashboardsService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private int convertToCellType(String columnType) {
|
|
|
+ private CellType convertToCellType(String columnType) {
|
|
|
switch (columnType) {
|
|
|
case "categorical":
|
|
|
- return HSSFCell.CELL_TYPE_STRING;
|
|
|
+ return CellType.STRING;
|
|
|
case "Timestamp":
|
|
|
- return 9;
|
|
|
+ return CellType.BLANK;
|
|
|
case "BigDecimal":
|
|
|
- return HSSFCell.CELL_TYPE_NUMERIC;
|
|
|
+ return CellType.NUMERIC;
|
|
|
case "scale":
|
|
|
- return HSSFCell.CELL_TYPE_NUMERIC;
|
|
|
+ return CellType.NUMERIC;
|
|
|
default:
|
|
|
- return HSSFCell.CELL_TYPE_STRING;
|
|
|
+ return CellType.STRING;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private HSSFCellStyle getCellStyle(HSSFWorkbook workbook) {
|
|
|
- HSSFCellStyle style = workbook.createCellStyle();
|
|
|
- Font font = workbook.createFont();
|
|
|
+ private XSSFCellStyle getCellStyle(XSSFWorkbook workbook) {
|
|
|
+ XSSFCellStyle style = workbook.createCellStyle();
|
|
|
+ XSSFFont font = workbook.createFont();
|
|
|
font.setFontName("仿宋_GB2312");// 字体
|
|
|
font.setFontHeightInPoints((short) 12);// 字号
|
|
|
- font.setBoldweight(new Short("8"));
|
|
|
+ font.setBold(true);
|
|
|
font.setColor((short)64);// 颜色
|
|
|
style.setFont(font);
|
|
|
- style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
|
|
|
- style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
style.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
|
|
|
- style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
|
|
|
- style.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
|
|
|
- style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
|
|
|
- style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
|
|
|
+ style.setBorderBottom(BorderStyle.MEDIUM);
|
|
|
+ style.setBorderLeft(BorderStyle.MEDIUM);
|
|
|
+ style.setBorderRight(BorderStyle.MEDIUM);
|
|
|
+ style.setBorderTop(BorderStyle.MEDIUM);
|
|
|
return style;
|
|
|
}
|
|
|
|