看到這個(gè)標(biāo)題,會(huì)很疑問(wèn),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è)簡(jiǎn)單的方法,這個(gè)方法只適用于excel簡(jiǎn)單的導(dǎo)出,直接通過(guò)輸出的頁(yè)面,然后設(shè)置頁(yè)面為輸出流的文件格式,這樣當(dāng)action轉(zhuǎn)向到j(luò)sp頁(yè)面的時(shí)候,直接就是將頁(yè)面輸出。
jsp頁(yè)面的代碼:
- <%@ page language="java" pageEncoding="UTF8"%>
- <html:html locale="true">
- <head>
- <title>LogExport</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <%
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/vnd.ms-excel;");
- response.setHeader("Content-Disposition", "attachment;filename=\""+new String("Log.xls".getBytes(),"ISO-8859-1")+"\"");
- %>
- </head>
- <body>
- <form action="/Action_export.do">
- <table width="100%" border="1" cellspacing="0" cellpadding="0" id="datagrid">
- <thead>
- <tr class="HeaderStyle" style="font-weight: normal;">
- <th>用戶</th>
- <th>姓名</th>
- <th>日期</th>
- <th>登錄IP</th>
- <th>主機(jī)名</th>
- <th colspan="3">
- <table width='100%' border="1" cellspacing="3" cellpadding="0" frame='void' >
- <tr><td colspan="3" style='background:transparent;' align="center">操作信息</td></tr>
- <tr style='background:transparent;'>
- <td width="40px" align="center">操作</td>
- <td width="100px" align="center">標(biāo)題</td>
- <td align="center">擴(kuò)展信息</td>
- </tr>
- </table>
- </th>
- </tr>
- </thead>
- <jsp:include page="common.jsp" flush="true" />
- </table>
- </form>
- </body>
- </html:html>