poi方法是匯出Excel

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.