第一步:查询出你要导出的数据。
<input type="submit" name="button" id="button" οnclick="goExcel()" value="导出Excel" class="button_style1" />
<script language="javascript">
function goExcel(){
window.open("${ctx}/acceptmanager.do?method=queryAcceptReport&find=1&expert=Excel","parent");
}
</script>
第二步:写一个JSP页面,循环查询出来的数据
代码示例
<%@ page language="java" contentType="application/msexcel;charset=GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
response.setHeader("Content-disposition","inline; filename=result.xls");//注意这句代码
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div align="center" style="font-size: 24px;"><b>查询</b></div>
<br/>
<div align="center" style="font-size: 16px;">
<b>(${year}年)</b></div>
<br/>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> 序号 </td>
<td> 名称 </td>
<td> 推荐项目数 </td>
<td> 受理项目数 </td>
<td> 受理比例 </td>
<td> 备注 </td>
</tr>
<c:forEach items="${rslist}" var="i" varStatus="status">
<tr>
<td>${status.count}</td>
<td>
<c:if test="${empty i[0]}">
</c:if>${i[0]}
</td>
<td>
<c:if test="${empty i[1]}">
</c:if>
${i[1]}
</td>
<td>
<c:if test="${empty i[2]}">
</c:if>
${i[2]}
</td>
<td>
<c:if test="${empty i[3]}">
</c:if>
${i[3]}%
</td>
<td> </td>
</tr>
</c:forEach>
</table>
</body>
</html>
如此excel就导出了,简单吧!