控制器
public void getAdministrativeProblem(HttpServletRequest request,HttpServletResponse response, StatisticalVo statisticalVo) throws IOException {
SessionVo sessionVo = getSessionVo(request);
AppServiceRequestInfo requestInfo=new AppServiceRequestInfo();
AppServiceRequestParam params=new AppServiceRequestParam();
params.setOrgId(sessionVo.getOrganId());
params.setStartDate(statisticalVo.getStartDate());
params.setEndDate(statisticalVo.getEndDate());
requestInfo.setParams(params);
SessionVo svo = this.getSessionVo(request);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
String excelName = "重-" + DateUtil.nowDate("yyyyMMdd_HHmmssSSS");
response.setHeader("content-disposition", "attachment;filename="
+ RequestUtil.getDownloadFileName(request, excelName + ".xlsx"));
response.setCharacterEncoding("utf-8");
XSSFWorkbook wb = performancePoliceApiService.getKeyUnitsExcel(requestInfo);
OutputStream outPutStream = response.getOutputStream();
wb.write(outPutStream);
outPutStream.flush();
outPutStream.close();
}
实现类
public XSSFWorkbook getKeyUnits2Excel(AppServiceRequestInfo requestInfo) {
XSSFWorkbook wb = new XSSFWorkbook();
// 列名
XSSFFont titleFont = wb.createFont();
titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
titleFont.setFontHeightInPoints((short) 13);
// 列名样式
XSSFCellStyle titleStyle = wb.createCellStyle();
titleStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
titleStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
titleStyle.setWrapText(false);
titleStyle.setFont(titleFont);
// 不合格字体
XSSFFont unQualifiedFont = wb.createFont();
unQualifiedFont.setFontHeightInPoints((short) 13);
unQualifiedFont.setColor(HSSFColor.RED.index);
// 不合格样式
XSSFCellStyle unQualifiedStyle = wb.createCellStyle();
unQualifiedStyle.setFont(unQualifiedFont);
List<Long> list=organizationService.findByLevelList();
for(int i=0;i<list.size();i++) {
if (getKeyUnitsWeb(requestInfo, list.get(i).toString()).size() != 0) {
XSSFSheet sheet = wb.createSheet("第" + (i + 1) + "层级");
sheet.setColumnWidth(0, 7000);
sheet.setColumnWidth(1, 7000);
sheet.setColumnWidth(2, 7000);
sheet.setColumnWidth(3, 7000);
XSSFRow row0 = sheet.createRow((short) 0);
XSSFCell cell0 = row0.createCell((short) 0);
cell0.setCellStyle(titleStyle);
cell0.setCellValue("公");
XSSFCell cell1 = row0.createCell((short) 1);
cell1.setCellStyle(titleStyle);
cell1.setCellValue("上");
XSSFCell cell2 = row0.createCell((short) 2);
cell2.setCellStyle(titleStyle);
cell2.setCellValue("检");
XSSFCell cell3 = row0.createCell((short) 3);
cell3.setCellStyle(titleStyle);
cell3.setCellValue("检");
List<ProblemVo> policeTaskList = getPoliceCaseWeb(requestInfo, list.get(i).toString());
int rowNum = 1;
for (ProblemVo p : policeTaskList) {
XSSFRow row = sheet.createRow(rowNum);
XSSFCell cell = row.createCell((short) 0);
cell.setCellValue(p.getName());
cell = row.createCell((short) 1);
cell.setCellValue(p.getParentName());
cell = row.createCell((short) 2);
cell.setCellValue(p.getEntherCount());
cell = row.createCell((short) 3);
cell.setCellValue(p.getProblemCount());
rowNum++;
}
}
}
return wb;
}