87,910
社区成员
发帖
与我相关
我的任务
分享
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=GBK">
</head>
<body>
<form id="frm1" action="DownExcel.jsp" target="_blank" style="margin:0;padding:0;" method="POST">
<input type="hidden" name="body" value="" />
</form>
<script type="text/javascript">
function downXLS() {
// 把表格内容用表单 POST 到 DownXLS.jsp
var tab = document.getElementById("tab1");
var frm = document.getElementById("frm1");
frm.body.value = tab.innerHTML;
frm.submit();
}
</script>
<table id="tab1" border="1" cellspacing="1" cellpadding="1">
<tr><td colspan="5" align="center">WEB页面导出为EXCEL文档的方法 </td></tr>
<tr>
<td>列标题1 </td>
<td>列标题2 </td>
<td>列标题3 </td>
<td>列标题4 </td>
<td>列标题5 </td>
</tr>
<tr>
<td>aaa </td>
<td>bbb </td>
<td>ccc </td>
<td>ddd </td>
<td>eee </td>
</tr>
<tr>
<td>AAA </td>
<td>BBB </td>
<td>CCC </td>
<td>DDD </td>
<td>EEE </td>
</tr>
<tr>
<td>FFF </td>
<td>GGG </td>
<td>HHH </td>
<td>III </td>
<td>JJJ </td>
</tr>
</table>
<input type="button" value="down" onclick="javascript: downXLS();" />
</body>
</html>
<%@ page language="java" pageEncoding="GBK"%>
<%
response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment; filename=stat.xls");
request.setCharacterEncoding("GBK");
String body = request.getParameter("body");
//System.out.println(body);
%>
<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=GBK">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>2</x:ActiveRow>
<x:ActiveCol>1</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>9090</x:WindowHeight>
<x:WindowWidth>11715</x:WindowWidth>
<x:WindowTopX>240</x:WindowTopX>
<x:WindowTopY>90</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1">
<% out.print(body); %>
</table>
</body>
</html>