页面1<input type="hidden" name="context" value="">
<span id="repexcel"> 
<table id="tableid" border="1"> 
<tr> <td>第一个单元格 </td> <td>第二个单元格 </td> <td>第三个单元格 </td> 
</tr> 
<tr> <td>第四个单元格 </td> <td>第五个单元格 </td> <td>第六个单元格 </td> 
</tr> 
</table> </span>
<input type="button" value="导出EXCEL表格" onclick="GoExcel();"> 
function GoExcel()
{
var oldaction=document.form.action;
document.form.action="IntoExcel.jsp";
document.all.context.value=document.all.repexcel.innerHTML;
document.form.submit();
document.form.action=oldaction;
}页面2  IntoExcel.jsp<%
String accountno = (request.getParameter("accountno")!=null)?request.getParameter("accountno"):"";
String jeperiod = (request.getParameter("jeperiod")!=null)?request.getParameter("jeperiod"):"";
response.setContentType("applicationpeng/ms-download");
response.setHeader("Content-Disposition", "attachment;filename=Report.xls");String text="<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"></head><body><TABLE   border=1 align=center cellPadding=2 cellSpacing=1 width='100%'>"+request.getParameter("context")+"</table></body></html>";
response.getWriter().println(text);
response.getWriter().close();
%>