当触发导出excel表格动作时,指定跳到下面这个JSP页面,浏览器会自动弹出下载提示框。
表格的格式会按html的格式展现。
<%@ page contentType="application/vnd.ms-excel; charset=gbk" %>
<%@ page language="java" pageEncoding="GBK"%>
<%
String filename = new String(("表格名").getBytes("GBK"),"ISO-8859-1");
response.addHeader("Content-Disposition", "filename=" + filename + ".xls");
%>
<html>
<head>
<meta name="Generator" content="Microsoft Excel 11">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<center><b>表格名</b></center><br>
<table border="1" align="center" cellpadding="0" cellspacing="1">
<tr >
<td>
<!--在这里用html写表格内容的代码,可以用jsp代码-->
</td>
</tr>
</table>
</body>
</html>
表格的格式会按html的格式展现。