参数格式

valueMap.put("values", listDatas);
String[] headers = { "项目名称", "楼栋名称", "单元名称", "楼层名称", "房间名称", "业主/租户姓名", "房间状态", "房间功能","认证人数" };
deriveUtils(headers, valueMap,"认证统计", response, request,null,null);

导出方法

private void deriveUtils(String[] headers,Map<String, Object> valueMap, String xlsName, HttpServletResponse response, HttpServletRequest request, Object o, Object o1) throws IOException {
response.reset();
response.setContentType("application/vnd.ms-excel");
Integer date = DateUtil.getNowTime();// 当前时间
String fileName = xlsName + date + ".xls";
UploadUtil.setFileDownloadHeader(request, response, fileName);
List<Map<String, Object>> list = (List<Map<String, Object>>) valueMap.get("values");
HSSFWorkbook web = new HSSFWorkbook();// 建立新HSSFWorkbook对象
Integer count = list.size();
Integer num = count%50000;
Integer num1;
if(num==0){
num1=count/50000;
}else{
num1=count/50000+1;
}
HSSFCellStyle titleStyle = web.createCellStyle();
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setLocked(false);
HSSFCell cell = null;
HSSFSheet sheet = null; //分页
HSSFRow row = null;
Integer n=0;
for(int q=1;q<=num1;q++){
sheet = web.createSheet(xlsName+n.toString());// 建立新的sheet对象
n++;

row = sheet.createRow(0);
/** 根据title的字符的长度设置列的宽度 */
for (int j = 0; j < headers.length; j++) {
sheet.setColumnWidth(j, 256 * (headers[j].length() + 10) + 184);
cell = row.createCell(j);
cell.setCellValue(headers[j]);
cell.setCellType(CellType.STRING);
cell.setCellStyle(titleStyle);
}
HSSFCellStyle valueStyle = web.createCellStyle();
for (int i = 50000*q-50000; i < 50000*q && i<count; i++) {
row = sheet.createRow(i-50000*q+50001);
int columnIndex = 0;//增加列
Map<String, Object> map = list.get(i);
Object[] content = new Object[headers.length];
content[0]=map.get("hName");
content[1]=map.get("bName");
content[2]=map.get("uName");
content[3]=map.get("fName");
content[4]=map.get("pName");
content[5]=map.get("cName");
content[6]=map.get("pState");
content[7]=map.get("pFunction");
content[8]=map.get("pNum");
for (int j = 0; j < content.length; j++) {
cell = row.createCell(j);
if (content[j] == null) {
content[j] = "";
}
HSSFRichTextString text = new HSSFRichTextString(content[j].toString());
cell.setCellValue(text);
}
}

}
try (OutputStream out = response.getOutputStream()) {
web.write(out);
out.flush();
} catch (IOException e) {
log.error(e.getMessage(),e);
}finally{
web.close();
}

}