Excel导出方法 添加时间范围

This commit is contained in:
leijun
2018-12-20 17:18:34 +08:00
parent 5f99f6beb4
commit e916254c93
5 changed files with 182 additions and 17 deletions

View File

@@ -1778,6 +1778,7 @@ public class ExportExcel {
return styles;
}
/**
* 添加一行
@@ -1963,6 +1964,10 @@ public class ExportExcel {
}
}
if(!StringUtil.isEmpty(val)){
if (val instanceof Date){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
val=sdf.format(val);
}
val = Encodes.unescapeHtml(String.valueOf(val));
}
@@ -2108,7 +2113,7 @@ public class ExportExcel {
* @param groups 导入分组
* @return
*/
public ExportExcel(Properties msgProp,List<String> titleList,Map<String,String> noExportMap,Map<String, Class<?>> clsMap, int type, int... groups){
public ExportExcel(Properties msgProp,List<String> titleList,Map<String,String> noExportMap,Map<String, Class<?>> clsMap, int type,String titleTime, int... groups){
Map<String, List<String>> headerMap=new HashMap<String, List<String>>();
Map<String, List<String>> commentMap=new HashMap<String, List<String>>();
for (String title : titleList) {
@@ -2226,7 +2231,7 @@ public class ExportExcel {
commentMap.put(title, commentList);
annotationMap.put(title, annotationList);
}
initializeMultiSheet(msgProp,titleList, headerMap,commentMap);
initializeMultiSheet(msgProp,titleList, headerMap,commentMap,titleTime);
}
/**
@@ -2234,7 +2239,7 @@ public class ExportExcel {
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
*/
private void initializeMultiSheet(Properties msgProp,List<String> titleList,Map<String, List<String>> headerMap,Map<String,List<String>> commentMap) {
private void initializeMultiSheet(Properties msgProp,List<String> titleList,Map<String, List<String>> headerMap,Map<String,List<String>> commentMap,String titleTime) {
this.wb = new SXSSFWorkbook(500);
int j=0;
sheets=new HashMap<>();
@@ -2249,13 +2254,31 @@ public class ExportExcel {
}
Sheet sheet = wb.createSheet(titleName);
num++;
rownums.put(title, 0);
if(!StringUtils.isEmpty(titleTime)){
rownums.put(title, 1);
}else{
rownums.put(title, 0);
}
sheets.put(title, sheet);
this.styles = createStyles(wb);
// Create header
if (headerList == null){
throw new RuntimeException("headerList not null!");
}
if(!StringUtils.isEmpty(titleTime)){
//添加一行数据
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,headerList.size()-1);
CellStyle style = styles.get("data");
Row timeRow = sheet.createRow(0);
timeRow.setHeightInPoints(16);
Cell cellt = timeRow.createCell(0);
cellt.setCellStyle(style);
cellt.setCellValue(titleTime);
sheet.addMergedRegion(callRangeAddress);
sheet.autoSizeColumn(0);
//--------------------
}
Integer rownum=rownums.get(title);
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
@@ -2283,9 +2306,6 @@ public class ExportExcel {
log.debug("Initialize success.");
}
/**
* 输出数据流
* @param os 输出数据流