实时报表Excel导出调整为后台导出

This commit is contained in:
leijun
2019-01-03 18:44:13 +08:00
parent d632670e45
commit ec7e93504c
6 changed files with 210 additions and 13 deletions

View File

@@ -2616,5 +2616,60 @@ public class ExportExcel {
log.debug("Export success.");
*/
}
public <E> ExportExcel ajaxDataList(List<List<Object>>dataMap,String code){
for (int i = 0; i < dataMap.size(); i++) {
Row row = this.addRow(sheets.get(code),rownums.get(code),code);
int colunm = 0;
List<Object> list=dataMap.get(i);
for (int j = 0; j < list.size(); j++) {
this.addCell(row, colunm++,list.get(j), 0,null);
}
}
return this;
}
public ExportExcel(String titleName,String code,String titleTime,List<String> headerList){
this.wb = new SXSSFWorkbook(500);
int j=0;
sheets=new HashMap<>();
rownums=new HashMap<>();
Sheet sheet = wb.createSheet(titleName);
if(!StringUtils.isEmpty(titleTime)){
rownums.put(code, 1);
}else{
rownums.put(code, 0);
}
sheets.put(code, sheet);
this.styles = createStyles(wb);
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.setCellValue(titleTime);
sheet.addMergedRegion(callRangeAddress);
sheet.autoSizeColumn(0);
setBorderStyle(CellStyle.BORDER_THIN,callRangeAddress,sheet,wb);
}
Integer rownum=rownums.get(code);
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i < headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellStyle(styles.get("header"));
cell.setCellValue(headerList.get(i));
sheet.autoSizeColumn(i);
}
for (int i = 0; i < headerList.size(); i++) {
int colWidth = sheet.getColumnWidth(i)*2;
sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
}
j++;
}
}