小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

利用jxl將數(shù)據(jù)導(dǎo)出到excel時彈出保存對話框的例子

 dawn001 2014-09-22
Java代碼  收藏代碼
  1. public String outPutExcel(ModelMap model, HttpServletRequest request,  
  2.                               HttpServletResponse response) {  
  3.   
  4.         //獲取時間區(qū)域  
  5.         String timeArea = request.getParameter("timeArea");  
  6.         String keyword = request.getParameter("keyword");  
  7.         String select = request.getParameter("select");  
  8.         //獲取操作類型  
  9.         String operate = request.getParameter("operate");  
  10.   
  11.         //        File file = new File("daily.xls");  
  12.         try {  
  13.             OutputStream os = response.getOutputStream();// 取得輸出流     
  14.             response.reset();// 清空輸出流     
  15.             response.setHeader("Content-disposition""attachment; filename="  
  16.                                                       + new String("daily".getBytes("GB2312"),  
  17.                                                           "iso8859_1") + ".xls");// 設(shè)定輸出文件頭     
  18.             response.setContentType("application/msexcel");// 定義輸出類型   
  19.   
  20.             WritableWorkbook workbook = Workbook.createWorkbook(os);  
  21.             if (workbook != null) {  
  22.   
  23.                 WritableSheet sheet = workbook.createSheet("sheet1"0);  
  24.   
  25.                 // 設(shè)置標題 sheet.addCell(new jxl.write.Label(列(從0開始), 行(從0開始), 內(nèi)容.));   
  26.                 try {  
  27.                     sheet.addCell(new Label(00"區(qū)域名"));  
  28.                     sheet.addCell(new Label(10"所在位置"));  
  29.                     sheet.addCell(new Label(20"操作人員"));  
  30.                     sheet.addCell(new Label(30"時間"));  
  31.                     sheet.addCell(new Label(40"操作類型"));  
  32.                     sheet.addCell(new Label(50"備注"));  
  33.   
  34.                     // 設(shè)置單元格的寬度   
  35.                     sheet.setColumnView(020);  
  36.                     sheet.setColumnView(140);  
  37.                     sheet.setColumnView(215);  
  38.                     sheet.setColumnView(330);  
  39.                     sheet.setColumnView(415);  
  40.                     sheet.setColumnView(520);  
  41.   
  42.                     //添加數(shù)據(jù)  
  43.                     List<SysActionLog> list = this.getSysActionLogs(timeArea, keyword, select,  
  44.                         operate);  
  45.   
  46.                     SysActionLog log = null;  
  47.                     for (int r = 0; r < list.size(); r++) { //行編號  
  48.                         log = list.get(r);  
  49.                         //區(qū)域名  
  50.                         sheet.addCell(new Label(0, r + 1, log.getFilealia()));  
  51.                         //所在位置  
  52.                         sheet.addCell(new Label(1, r + 1, log.getFilename()));  
  53.                         //操作人員  
  54.                         sheet.addCell(new Label(2, r + 1, log.getAuthor()));  
  55.                         //時間  
  56.                         sheet.addCell(new Label(3, r + 1, log.getFormatDate()));  
  57.                         //操作類型  
  58.                         sheet.addCell(new Label(4, r + 1, log.getSysAction().getMessage()));  
  59.                         //備注  
  60.                         sheet.addCell(new Label(5, r + 1, log.getComment()));  
  61.                     }  
  62.   
  63.                     //從內(nèi)存中寫入文件中     
  64.                     workbook.write();  
  65.                     //關(guān)閉資源,釋放內(nèi)存      
  66.                     workbook.close();  
  67.   
  68.                     /*response.reset(); 
  69.                     FileInputStream f = new FileInputStream(file); 
  70.                     byte[] fb = new byte[f.available()]; 
  71.                     f.read(fb); 
  72.                     response 
  73.                         .setHeader("Content-disposition", "attachment; filename=" 
  74.                                                           + new String("daily.xls" 
  75.                                                               .getBytes("gb2312"), "iso8859-1")); 
  76.                     ByteArrayInputStream bais = new ByteArrayInputStream(fb); 
  77.                     int b; 
  78.                     while ((b = bais.read()) != -1) { 
  79.                         response.getOutputStream().write(b); 
  80.                     } 
  81.                     response.getOutputStream().flush(); 
  82.                      
  83.                     //刪除服務(wù)器上的文件 
  84.                     file.deleteOnExit();*/  
  85.   
  86.                 } catch (RowsExceededException e) {  
  87.                     logger.error("sheet不存在", e);  
  88.                 } catch (WriteException e) {  
  89.                     logger.error("創(chuàng)建列名出錯", e);  
  90.                 }  
  91.             }  
  92.   
  93.         } catch (IOException e) {  
  94.             logger.error("文件創(chuàng)建出錯", e);  
  95.         }  
  96.         return "daily.vm";  
  97.     }  

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約