导出excel

Raod 3 years ago
parent 8941a4e9f4
commit 053807da69

@ -0,0 +1,73 @@
package com.anjiplus.template.gaea.business.enums;
/**
* @author zhouhang
* @description EXCEL
* @date 2021/4/26
*/
public enum ExcelCenterStyleEnum {
/**
*
*/
LEFT((short) 1, 1, "左对齐"),
/**
*
*/
RIGHT((short) 3, 2, "右对齐"),
/**
*
*/
CENTER((short) 2, 0, "居中"),
;
/**
* excelcode
*/
private final short excelCode;
/**
* 线code
*/
private final Integer onlineExcelCode;
/**
*
*/
private final String name;
public Integer getOnlineExcelCode() {
return onlineExcelCode;
}
public String getName() {
return name;
}
public short getExcelCode() {
return excelCode;
}
ExcelCenterStyleEnum(short excelCode, Integer onlineExcelCode, String name) {
this.excelCode = excelCode;
this.onlineExcelCode = onlineExcelCode;
this.name = name;
}
/**
* @param code excelcode
* @return Enum_ExcelCenterStyle
* @description excel线
* @author zhouhang
* @date 2021/4/26
*/
public static ExcelCenterStyleEnum getExcelCenterStyleByExcelCenterCode(short code) {
for (ExcelCenterStyleEnum value : ExcelCenterStyleEnum.values()) {
if (code == value.getExcelCode()) {
return value;
}
}
return CENTER;
}
}

@ -8,6 +8,7 @@ import java.util.List;
/** /**
* *
*
* @author Administrator * @author Administrator
*/ */
@Data @Data

@ -13,31 +13,49 @@ import java.io.Serializable;
*/ */
@Data @Data
public class ReportExcelDto extends GaeaBaseDTO implements Serializable { public class ReportExcelDto extends GaeaBaseDTO implements Serializable {
/** 报表名称 */ /**
*
*/
private String reportName; private String reportName;
/** 报表编码 */ /**
*
*/
private String reportCode; private String reportCode;
/**数据集编码,以|分割*/ /**
* |
*/
private String setCodes; private String setCodes;
/** 分组 */ /**
*
*/
private String reportGroup; private String reportGroup;
/** 数据集查询参数 */ /**
*
*/
private String setParam; private String setParam;
/** 报表json字符串 */ /**
* json
*/
private String jsonStr; private String jsonStr;
/** 报表类型 */ /**
*
*/
private String reportType; private String reportType;
/** 数据总计 */ /**
*
*/
private long total; private long total;
/**导出类型*/ /**
*
*/
private String exportType; private String exportType;
} }

@ -12,7 +12,7 @@ import java.io.Serializable;
* @date 2021/4/13 15:12 * @date 2021/4/13 15:12
*/ */
@Data @Data
public class ReportExcelParam extends PageParam implements Serializable{ public class ReportExcelParam extends PageParam implements Serializable {
} }

@ -9,7 +9,7 @@ import lombok.Data;
* @author chenkening * @author chenkening
* @date 2021/4/13 15:11 * @date 2021/4/13 15:11
*/ */
@TableName(value="gaea_report_excel") @TableName(value = "gaea_report_excel")
@Data @Data
public class ReportExcel extends GaeaBaseEntity { public class ReportExcel extends GaeaBaseEntity {

@ -18,7 +18,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -48,11 +47,11 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Override @Override
public ReportExcelDto detailByReportCode(String reportCode) { public ReportExcelDto detailByReportCode(String reportCode) {
QueryWrapper<ReportExcel> queryWrapper = new QueryWrapper<>(); QueryWrapper<ReportExcel> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("report_code" , reportCode); queryWrapper.eq("report_code", reportCode);
ReportExcel reportExcel = reportExcelMapper.selectOne(queryWrapper); ReportExcel reportExcel = reportExcelMapper.selectOne(queryWrapper);
if(reportExcel != null){ if (reportExcel != null) {
ReportExcelDto dto = new ReportExcelDto(); ReportExcelDto dto = new ReportExcelDto();
BeanUtils.copyProperties(reportExcel , dto); BeanUtils.copyProperties(reportExcel, dto);
return dto; return dto;
} }
return null; return null;
@ -84,13 +83,13 @@ public class ReportExcelServiceImpl implements ReportExcelService {
// 根据id查询 报表详情 // 根据id查询 报表详情
ReportExcel reportExcel = selectOne("report_code", reportExcelDto.getReportCode()); ReportExcel reportExcel = selectOne("report_code", reportExcelDto.getReportCode());
QueryWrapper<Report> queryWrapper = new QueryWrapper<>(); QueryWrapper<Report> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("report_code" , reportExcelDto.getReportCode()); queryWrapper.eq("report_code", reportExcelDto.getReportCode());
Report report = reportMapper.selectOne(queryWrapper); Report report = reportMapper.selectOne(queryWrapper);
GaeaAssert.notNull(reportExcel, ResponseCode.RULE_CONTENT_NOT_EXIST, "reportExcel"); GaeaAssert.notNull(reportExcel, ResponseCode.RULE_CONTENT_NOT_EXIST, "reportExcel");
String setParam = reportExcelDto.getSetParam(); String setParam = reportExcelDto.getSetParam();
GaeaBeanUtils.copyAndFormatter(reportExcel , reportExcelDto); GaeaBeanUtils.copyAndFormatter(reportExcel, reportExcelDto);
if(StringUtils.isNotBlank(setParam)){ if (StringUtils.isNotBlank(setParam)) {
reportExcelDto.setSetParam(setParam); reportExcelDto.setSetParam(setParam);
} }
reportExcelDto.setReportName(report.getReportName()); reportExcelDto.setReportName(report.getReportName());

@ -1,7 +1,6 @@
package com.anjiplus.template.gaea.business.modules.reportexcel.util; package com.anjiplus.template.gaea.business.modules.reportexcel.util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFPalette; import org.apache.poi.hssf.usermodel.HSSFPalette;
@ -15,6 +14,7 @@ import org.apache.poi.xssf.usermodel.XSSFColor;
/** /**
* https://github.com/mengshukeji/LuckysheetServer * https://github.com/mengshukeji/LuckysheetServer
*
* @author Administrator * @author Administrator
*/ */
@Slf4j @Slf4j
@ -22,22 +22,22 @@ public class ColorUtil {
private static final String S = "0123456789ABCDEF"; private static final String S = "0123456789ABCDEF";
public static Short getColorByStr(String colorStr){ public static Short getColorByStr(String colorStr) {
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
HSSFPalette palette = workbook.getCustomPalette(); HSSFPalette palette = workbook.getCustomPalette();
if(colorStr.toLowerCase().startsWith("rgb")){ if (colorStr.toLowerCase().startsWith("rgb")) {
colorStr=colorStr.toLowerCase().replace("rgb(","").replace(")",""); colorStr = colorStr.toLowerCase().replace("rgb(", "").replace(")", "");
String[] colors=colorStr.split(","); String[] colors = colorStr.split(",");
if(colors.length==3){ if (colors.length == 3) {
try{ try {
int red = Integer.parseInt(colors[0].trim(),16); int red = Integer.parseInt(colors[0].trim(), 16);
int green = Integer.parseInt(colors[1].trim(),16); int green = Integer.parseInt(colors[1].trim(), 16);
int blue = Integer.parseInt(colors[2].trim(),16); int blue = Integer.parseInt(colors[2].trim(), 16);
HSSFColor hssfColor=palette.findSimilarColor(red,green,blue); HSSFColor hssfColor = palette.findSimilarColor(red, green, blue);
return hssfColor.getIndex(); return hssfColor.getIndex();
}catch (Exception ex){ } catch (Exception ex) {
log.error(ex.toString()); log.error(ex.toString());
return null; return null;
} }
@ -45,27 +45,27 @@ public class ColorUtil {
return null; return null;
} }
if(colorStr.equals("#000")){ if (colorStr.equals("#000")) {
colorStr="#000000"; colorStr = "#000000";
} }
if(colorStr!=null && colorStr.length()>=6){ if (colorStr != null && colorStr.length() >= 6) {
try{ try {
if(colorStr.length()==8){ if (colorStr.length() == 8) {
colorStr=colorStr.substring(2); colorStr = colorStr.substring(2);
} }
if(colorStr.length()==7){ if (colorStr.length() == 7) {
colorStr=colorStr.substring(1); colorStr = colorStr.substring(1);
} }
String str2 = colorStr.substring(0,2); String str2 = colorStr.substring(0, 2);
String str3 = colorStr.substring(2,4); String str3 = colorStr.substring(2, 4);
String str4 = colorStr.substring(4,6); String str4 = colorStr.substring(4, 6);
int red = Integer.parseInt(str2,16); int red = Integer.parseInt(str2, 16);
int green = Integer.parseInt(str3,16); int green = Integer.parseInt(str3, 16);
int blue = Integer.parseInt(str4,16); int blue = Integer.parseInt(str4, 16);
HSSFColor hssfColor=palette.findSimilarColor(red,green,blue); HSSFColor hssfColor = palette.findSimilarColor(red, green, blue);
return hssfColor.getIndex(); return hssfColor.getIndex();
}catch (Exception ex){ } catch (Exception ex) {
log.error(ex.toString()); log.error(ex.toString());
return null; return null;
} }

@ -346,7 +346,7 @@ public class XlsSheetUtil {
if ("border-outside".equals(borderType)) { if ("border-outside".equals(borderType)) {
//外圈边框 //外圈边框
if (row_ == rowList.getInteger(0) ) { if (row_ == rowList.getInteger(0)) {
style.setBorderTop(BorderStyle.valueOf(style_)); //顶部边框 style.setBorderTop(BorderStyle.valueOf(style_)); //顶部边框
style.setTopBorderColor(color);//顶部边框颜色 style.setTopBorderColor(color);//顶部边框颜色
} }
@ -365,49 +365,34 @@ public class XlsSheetUtil {
} }
if ("border-inside".equals(borderType)) { if ("border-horizontal".equals(borderType) || "border-inside".equals(borderType)) {
//所有内边框
if (row_ >= rowList.getInteger(0) && row_ < rowList.getInteger(rowList.size() - 1)) {
style.setBorderRight(BorderStyle.valueOf(style_)); //右边框
style.setRightBorderColor(color);//右边框颜色
style.setBorderBottom(BorderStyle.valueOf(style_)); //底部边框
style.setBottomBorderColor(color);//底部边框颜色 }
}
if (col_ >= columnList.getInteger(0) && col_ < columnList.getInteger(columnList.size() - 1)) {
style.setBorderRight(BorderStyle.valueOf(style_)); //右边框
style.setRightBorderColor(color);//右边框颜色
style.setBorderBottom(BorderStyle.valueOf(style_)); //底部边框
style.setBottomBorderColor(color);//底部边框颜色 }
}
}
if ("border-horizontal".equals(borderType)) {
//内部横线 //内部横线
if (row_ >= rowList.getInteger(0) && row_ < rowList.getInteger(rowList.size() - 1)) { if (row_ >= rowList.getInteger(0)
style.setBorderBottom(BorderStyle.valueOf(style_)); //底部边框 && row_ < rowList.getInteger(rowList.size() - 1)
style.setBottomBorderColor(color);//底部边框颜色 } && col_ >= columnList.getInteger(0)
} && col_ <= columnList.getInteger(columnList.size() - 1)) {
if (col_ >= columnList.getInteger(0) && col_ < columnList.getInteger(columnList.size() - 1)) {
style.setBorderBottom(BorderStyle.valueOf(style_)); //底部边框 style.setBorderBottom(BorderStyle.valueOf(style_)); //底部边框
style.setBottomBorderColor(color);//底部边框颜色 } style.setBottomBorderColor(color);//底部边框颜色 }
} }
} }
if ("border-vertical".equals(borderType)) { if ("border-vertical".equals(borderType) || "border-inside".equals(borderType)) {
//内部竖线 //内部竖线
if (row_ >= rowList.getInteger(0) && row_ < rowList.getInteger(rowList.size() - 1)) { if (row_ >= rowList.getInteger(0)
style.setBorderRight(BorderStyle.valueOf(style_)); //右边框 && row_ <= rowList.getInteger(rowList.size() - 1)
style.setRightBorderColor(color);//右边框颜色 && col_ >= columnList.getInteger(0)
} && col_ < columnList.getInteger(columnList.size() - 1)) {
if (col_ >= columnList.getInteger(0) && col_ < columnList.getInteger(columnList.size() - 1)) {
style.setBorderRight(BorderStyle.valueOf(style_)); //右边框 style.setBorderRight(BorderStyle.valueOf(style_)); //右边框
style.setRightBorderColor(color);//右边框颜色 style.setRightBorderColor(color);//右边框颜色
} }
} }
if ("border-none".equals(borderType)) {
style.setBorderLeft(BorderStyle.NONE); //左边框
style.setBorderRight(BorderStyle.NONE); //左边框
style.setBorderTop(BorderStyle.NONE); //左边框
style.setBorderBottom(BorderStyle.NONE); //左边框
}
} }
} }

Loading…
Cancel
Save