Jason ---分享,共同進(jìn)步

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

          java web 導(dǎo)出excel

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

           

          jsp頁面的代碼:

          Java代碼 復(fù)制代碼
          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>主機(jī)名</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">標(biāo)題</td>   
          31.                                     <td align="center">擴(kuò)展信息</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 閱讀(2507) 評論(1)  編輯  收藏 所屬分類: java web

          評論

          # re: java web 導(dǎo)出excel [未登錄]  回復(fù)  更多評論   

          123123123123
          2013-05-17 14:53 | 123
          主站蜘蛛池模板: SHOW| 永嘉县| 临汾市| 庆阳市| 溆浦县| 遵化市| 甘德县| 永寿县| 怀来县| 乌兰浩特市| 七台河市| 大宁县| 孝义市| 大方县| 尚志市| 莱西市| 巨鹿县| 灵川县| 肥乡县| 江永县| 图们市| 康马县| 达拉特旗| 鄯善县| 闻喜县| 无为县| 威远县| 深州市| 白山市| 沂南县| 遂溪县| 旺苍县| 灵山县| 台东县| 肇州县| 汪清县| 泾川县| 临城县| 高雄市| 万山特区| 上蔡县|