@Override protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook hssfWorkbook, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { List<TGcxxInvitationCode> list = (List<TGcxxInvitationCode>) map.get("map"); HSSFSheet sheet = hssfWorkbook.createSheet(); //创建表头 HSSFRow row = sheet.createRow(0); HSSFCell cell = null; String[] headers = new String[]{"姓名","手机","账号","邀请时间","注册时间"}; for(int i=0;i<headers.length;i++) { cell = row.createCell(i); cell.setCellValue(headers[i]); } //创建表内容 if(list != null & list.size()>0) { for(int m=0;m<list.size();m++) { HSSFRow bodyRow = sheet.createRow(m + 1); TGcxxInvitationCode invitation = list.get(m); cell = bodyRow.createCell(0); cell.setCellValue(invitation.getUserTruename()); cell = bodyRow.createCell(1); cell.setCellValue(invitation.getUserPhone()); cell = bodyRow.createCell(2); cell.setCellValue(invitation.getLoginName()); cell = bodyRow.createCell(3); cell.setCellValue(Util.formatDate(invitation.getCreateTime())); cell = bodyRow.createCell(4); cell.setCellValue(Util.formatDate(invitation.getCreateDate())); } } String filename = "被邀请人详情信息"; httpServletResponse.setContentType("application/vnd.ms-excel"); httpServletResponse.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(filename,"UTF-8") +".xls"); OutputStream outputStream = httpServletResponse.getOutputStream(); hssfWorkbook.write(outputStream); outputStream.flush(); outputStream.close(); }
时间: 2024-11-13 15:15:00