主要是通过文件流的方式,这个方法不是很好,如有更好的方法,还希望多多交流哦!
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.lang.*"%>
<%
try{
response.setContentType("Application/msexcel");
response.setHeader("Content-Disposition", "attachment;filename=test.xls");
StringBuffer cont=new StringBuffer("");
%>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
</HEAD>
<BODY>
<br/><br/><br/>
<%
cont.append("<table width='100%' border='1'>\r\n");
cont.append("<tr>\r\n");
cont.append("<td height='19'>字段一</td>\r\n");
cont.append("<td height='19'>字段二</td>\r\n");
cont.append("<td height='19'>字段三</td>\r\n");
cont.append("<td height='19'>字段四</td>\r\n");
cont.append("</tr>\r\n");
cont.append("<tr>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("</tr>\r\n");
cont.append("<tr>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("</table>\r\n");
response.getWriter().println(cont.toString());
response.getWriter().close();
}
catch (Exception e){
out.println(e.toString());
}
%>
</BODY>
</HTML>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.lang.*"%>
<%
try{
response.setContentType("Application/msexcel");
response.setHeader("Content-Disposition", "attachment;filename=test.xls");
StringBuffer cont=new StringBuffer("");
%>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
</HEAD>
<BODY>
<br/><br/><br/>
<%
cont.append("<table width='100%' border='1'>\r\n");
cont.append("<tr>\r\n");
cont.append("<td height='19'>字段一</td>\r\n");
cont.append("<td height='19'>字段二</td>\r\n");
cont.append("<td height='19'>字段三</td>\r\n");
cont.append("<td height='19'>字段四</td>\r\n");
cont.append("</tr>\r\n");
cont.append("<tr>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("</tr>\r\n");
cont.append("<tr>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("<td>"+"xxxxxxxxxxxxxxxxxxxxxxxx" +" </td>\r\n");
cont.append("</table>\r\n");
response.getWriter().println(cont.toString());
response.getWriter().close();
}
catch (Exception e){
out.println(e.toString());
}
%>
</BODY>
</HTML>