`
manjingtou
  • 浏览: 119137 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java web 导出excel

阅读更多

看到这个标题,会很疑问,java导出excel 有很多文章呀,都知道怎么用呀,呵呵,我也是这么认为,我们常用的就是jxl 或者poi ,现在jxl 代码不在更新不支持2007,一般都采用poi 进行excel的操作,今天在看系统(架构struts+ spring+ hibernate),需要做一个excel导出,一个简单的方法,这个方法只适用于excel简单的导出,直接通过输出的页面,然后设置页面为输出流的文件格式,这样当action转向到jsp页面的时候,直接就是将页面输出。

 

jsp页面的代码:

<%@ 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>主机名</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">标题</td>
									<td align="center">扩展信息</td>
								</tr>
							</table>
						</th>
					</tr>
				</thead>
				<jsp:include page="common.jsp" flush="true" />
			</table>
		</form>
	</body>
</html:html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics