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 阅读(2471) 评论(1)  编辑  收藏 所属分类: java web

评论

# re: java web 导出excel [未登录]  回复  更多评论   

123123123123
2013-05-17 14:53 | 123

只有注册用户登录后才能发表评论。


网站导航: