您的位置:首页 > 其它

excel文件的下载

2016-07-03 17:52 232 查看
@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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: