实时报表Excel导出调整为后台导出
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2277,6 +2277,24 @@ public class BaseController {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ExcelCsv.writeCSVFile(response,titleList,headMap,dataList,fileName,titleTime,msgProp);
|
||||
}
|
||||
|
||||
|
||||
public void _ajaxExport(HttpServletRequest request, HttpServletResponse response,
|
||||
String code,String titleTime,List<String> headerList, List<List<Object>> dataList)
|
||||
throws Exception{
|
||||
Properties msgProp = getMsgProp();
|
||||
String fileName = msgProp.getProperty(code, code) + "_" + DateUtils.getDate("yyyyMMddHHmmss")
|
||||
+ ".xlsx";
|
||||
fileName = fileName.replaceAll(" ", "_");
|
||||
if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
|
||||
fileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
} else {
|
||||
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
|
||||
}
|
||||
new ExportExcel(msgProp.getProperty(code, code),code,titleTime, headerList).ajaxDataList(dataList, code).write(response, fileName).dispose();
|
||||
|
||||
}
|
||||
|
||||
public String initLogMap(BaseLogEntity log,String title){
|
||||
Properties msgProp = getMsgProp();
|
||||
String logTime=msgProp.getProperty(title,title);;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.nis.web.controller.report;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/export")
|
||||
public class ExportController extends BaseController {
|
||||
|
||||
@RequestMapping(value = "ajaxExport")
|
||||
public void ajaxExport(String exports,HttpServletRequest request,HttpServletResponse response) throws Exception{
|
||||
JSONObject jsonObject = JSONObject.fromObject(StringEscapeUtils.unescapeHtml(exports));
|
||||
Map<String,Object> map=JSONObject.fromObject(jsonObject);
|
||||
List<List<Object>> list=(List<List<Object>>) map.get("book");
|
||||
List<String> heard=(List<String>) map.get("heard");
|
||||
String titleTime=String.valueOf(map.get("titleTime"));
|
||||
String titleCode=String.valueOf(map.get("titleCode"));
|
||||
_ajaxExport(request,response,titleCode, titleTime, heard, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user