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

poi方法是导出Excel

时间:2014-08-26 19:58:07      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:poi方法是导出excel

protected void renderMergedOutputModel(Map<String, Object> model,HttpServletRequest request, HttpServletResponse response)throws Exception {

Workbook wb = new XSSFWorkbook();    

CellStyle cellStyle = wb.createCellStyle();

Font font = wb.createFont();

        font.setColor(HSSFColor.RED.index);    //红色

        cellStyle.setFont(font);

        

Sheet sheet1 = (Sheet) wb.createSheet("FactoryComplainReason");  

Row rowHead = (Row) sheet1.createRow(0); 

Cell cellHead = rowHead.createCell(0); 

     cellHead.setCellValue("投诉时间");  

     cellHead = rowHead.createCell(1); 

     cellHead.setCellValue("订单编号"); 

     cellHead = rowHead.createCell(2); 

     cellHead.setCellValue("商品明细");

  for (int i = 1; i < 5; i++) {//行    

           Row row = (Row) sheet1.createRow(i);  

         

           //循环写入列数据     

           for (int j = 0; j < 3; j++) {  //列  

               Cell cell = row.createCell(j);    

               cell.setCellValue("测试"+j); 

               cell.setCellStyle(cellStyle);

           }    

       }    

  //1、以弹出下载框的方式导出

  response.addHeader("Content-Disposition", "attachment;filename=FactoryComplainReason.xlsx");  

  //创建文件流     

  response.setContentType("application/vnd.ms-excel;charset=gb2312");  

      OutputStream out = new BufferedOutputStream(response.getOutputStream()); 

      //2、以指定下载路径方式导出 -start

      //String path = "c:/";    

      //String fileName = "FactoryComplainReason3";    

      //String fileType = "xlsx";  

      //OutputStream out = new FileOutputStream(path+fileName+"."+fileType);    

      //以指定下载路径方式导出 -end

      //写入数据     

      wb.write(out);   

      out.flush();

      //关闭文件流     

      out.close();

}


poi方法是导出Excel

标签:poi方法是导出excel

原文地址:http://8757576.blog.51cto.com/8747576/1545266

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