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

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

          java web 導(dǎo)出excel

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

           

          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
          主站蜘蛛池模板: 西充县| 隆德县| 武强县| 湘乡市| 舟曲县| 邳州市| 东兴市| 大理市| 萨嘎县| 双峰县| 宾阳县| 上杭县| 迁安市| 岑巩县| 麻城市| 包头市| 崇文区| 中方县| 康平县| 永善县| 濉溪县| 扎囊县| 屯留县| 蕲春县| 宜宾市| 宽城| 郧西县| 铜川市| 怀安县| 旌德县| 武鸣县| 都江堰市| 商城县| 夹江县| 麻栗坡县| 石阡县| 麻江县| 乐至县| 开化县| 潜山县| 巴马|