POI 导出jsp 数据到excel

原创
2014/03/13 17:22
阅读数 1.9K

http://yangbobestone.iteye.com/blog/1123458



按照链接里面的思路 做的 

 public void saveSummaryInExcel(HttpServletRequest request,

      HttpServletResponse response) throws Exception {

    JewelCIUploadQuerySummaryFormBean formBean1 = (JewelCIUploadQuerySummaryFormBean) getData(

        JewelCIUploadQuerySummaryFormBean.class, request);

    List<JewelCiUploadFileSummaryVO> summaryList = jewelCIUploadQueryService

        .queryAllByParas(formBean1);

    HSSFWorkbook workBook = new HSSFWorkbook();

    HSSFSheet sheet = workBook.createSheet("summary list");

    sheet.setColumnWidth((short) 0, (short) 35);

    sheet.setColumnWidth((short) 1, (short) 50);

    sheet.setColumnWidth((short) 2, (short) 50);

    sheet.setColumnWidth((short) 3, (short) 50);

    sheet.setColumnWidth((short) 4, (short) 50);

    sheet.setColumnWidth((short) 5, (short) 50);

    sheet.setColumnWidth((short) 6, (short) 50);

    HSSFRow row = sheet.createRow((short) 0);

    HSSFCell cell[] = new HSSFCell[7];

    for (short i = 0; i < 7; i++) {

      cell[i] = row.createCell(i);

    }

    cell[0].setCellValue("Master Policy No.");

    cell[1].setCellValue("Upload Date");

    cell[2].setCellValue("File Name");

    cell[3].setCellValue("Status");

    cell[4].setCellValue("Date of Process");

    cell[5].setCellValue("Message");

    cell[6].setCellValue("User");

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    for (int i = 0; i < summaryList.size(); i++) {

      JewelCiUploadFileSummaryVO vo = summaryList.get(i);

      HSSFRow dataRow = sheet.createRow(i + 1);

      HSSFCell data[] = new HSSFCell[7];

      for (short j = 0; j < 7; j++) {

        data[j] = dataRow.createCell(j);

      }

      data[0].setCellValue(vo.getMpPolicyNo());

      data[1].setCellValue(sdf.format(vo.getUploadDate()));

      data[2].setCellValue(vo.getFileName());

      data[3].setCellValue(vo.getStatus());

      data[4].setCellValue(vo.getProcessDate());

      data[5].setCellValue(vo.getMessage());

      data[6].setCellValue(vo.getCustomName());

    }


    OutputStream out = null;

    out = response.getOutputStream();

    response.setHeader("Content-disposition", "attachment; filename="

        + "ciUploadSummary.xls");

    response.setContentType("application/msexcel;charset=UTF-8");

    response.setHeader("Pragma", "No-cache");

    response.setHeader("Cache-Control", "no-cache");

    response.setDateHeader("Expires", 0);

    workBook.write(out);

    out.flush();

    workBook.write(out);

    out.close();


  }


展开阅读全文
加载中
点击加入讨论🔥(2) 发布并加入讨论🔥
打赏
2 评论
8 收藏
0
分享
返回顶部
顶部