码迷,mamicode.com
首页 > 其他好文 > 详细

excel文件的下载

时间:2016-07-03 19:03:05      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

@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();
    }

 

excel文件的下载

标签:

原文地址:http://www.cnblogs.com/52hadoop/p/5638456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!