Jason ---分享,共同進步

          激情成就夢想,努力創造未來
          隨筆 - 53, 文章 - 1, 評論 - 45, 引用 - 0
          數據加載中……

          java web 導出excel

          看到這個標題,會很疑問,java導出excel 有很多文章呀,都知道怎么用呀,呵呵,我也是這么認為,我們常用的就是jxl 或者poi ,現在jxl 代碼不在更新不支持2007,一般都采用poi 進行excel的操作,今天在看系統(架構struts+ spring+ hibernate),需要做一個excel導出,一個簡單的方法,這個方法只適用于excel簡單的導出,直接通過輸出的頁面,然后設置頁面為輸出流的文件格式,這樣當action轉向到jsp頁面的時候,直接就是將頁面輸出。

           

          jsp頁面的代碼:

          Java代碼 復制代碼
          1. <%@ page language="java" pageEncoding="UTF8"%>   
          2. <html:html locale="true">   
          3.     <head>      
          4.         <title>LogExport</title>   
          5.         <meta http-equiv="pragma" content="no-cache">   
          6.         <meta http-equiv="cache-control" content="no-cache">   
          7.         <meta http-equiv="expires" content="0">   
          8.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">   
          9.         <%   
          10.           response.setCharacterEncoding("UTF-8");   
          11.           response.setContentType("application/vnd.ms-excel;");      
          12.           response.setHeader("Content-Disposition""attachment;filename=\""+new String("Log.xls".getBytes(),"ISO-8859-1")+"\"");   
          13.         %>     
          14.     </head>   
          15.     <body>   
          16.         <form action="/Action_export.do">   
          17.             <table width="100%" border="1" cellspacing="0" cellpadding="0" id="datagrid">   
          18.                 <thead>   
          19.                     <tr class="HeaderStyle" style="font-weight: normal;">   
          20.                         <th>用戶</th>   
          21.                         <th>姓名</th>   
          22.                         <th>日期</th>   
          23.                         <th>登錄IP</th>   
          24.                         <th>主機名</th>   
          25.                         <th colspan="3">   
          26.                          <table width='100%'  border="1" cellspacing="3" cellpadding="0" frame='void' >    
          27.                                 <tr><td colspan="3" style='background:transparent;' align="center">操作信息</td></tr>   
          28.                                 <tr style='background:transparent;'>   
          29.                                     <td width="40px" align="center">操作</td>   
          30.                                     <td width="100px" align="center">標題</td>   
          31.                                     <td align="center">擴展信息</td>   
          32.                                 </tr>   
          33.                             </table>   
          34.                         </th>   
          35.                     </tr>   
          36.                 </thead>   
          37.                 <jsp:include page="common.jsp" flush="true" />   
          38.             </table>   
          39.         </form>   
          40.     </body>   
          41. </html:html>  

          posted on 2012-11-03 12:45 agun 閱讀(2506) 評論(1)  編輯  收藏 所屬分類: java web

          評論

          # re: java web 導出excel [未登錄]  回復  更多評論   

          123123123123
          2013-05-17 14:53 | 123
          主站蜘蛛池模板: 隆回县| 公主岭市| 凤山县| 图木舒克市| 宜章县| 肇源县| 淳化县| 鸡东县| 柳江县| 佛冈县| 博兴县| 郎溪县| 通河县| 清徐县| 阜城县| 呼图壁县| 南投市| 曲靖市| 崇义县| 丰台区| 信阳市| 商水县| 平顺县| 阳春市| 茌平县| 香格里拉县| 长宁县| 双鸭山市| 永川市| 高淳县| 元阳县| 仙游县| 岳阳市| 安西县| 井陉县| 林口县| 黄山市| 夹江县| 黄平县| 蓝山县| 东海县|