来源:www.cncfan.com | 2006-8-9 | (有3929人读过)
给你一个完整的例子! <% response.Buffer=true %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>报表下载</title> </head> <body>
<!--#include file="..\conn.asp"--> <% 'on error resume next Set rs = Server.CreateObject("ADODB.Recordset") sql="select * from table" rs.Open sql,conn,1,1
if rs.EOF and rs.BOF then response.write "数据库没有记录!" response.end else %> <table width="700" border="1" align="center" bordercolor="#CCCCCC"> <tr> <td colspan="12"><div align="center"> </div></td> </tr> <tr> <td colspan="12"><div align="center">报表 </div></td> </tr> <tr> <td colspan="12"><div align="right"><%=request.form("year1")&"年"&request.form("month1")&"月"&request.form("day1")&"日--"&request.form("year2")&"年"&request.form("month2")&"月"&request.form("day2")&"日"%> </div></td> </tr> <tr> <td colspan="12"><div align="right">字段(元) </div></td> </tr> <tr> <td colspan="12"><div align="center"> </div></td> </tr> <tr> <td><div align="center">字段</div></td> <td><div align="center">字段期</div></td> <td><div align="center">设备字段</div></td> <td><div align="center">服务号</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> <td><div align="center">字段</div></td> </tr> <% do while not rs.eof %> <tr> <td> <div align="left"> <%=rs(0)%></div></td> <td> <div align="left"> <%=rs(1)%></div></td> <td> <div align="left"> <%=rs(2)%></div></td> <td> <div align="left"> <%=rs(3)%></div></td> <td> <div align="left"> <%=rs(4)%></div></td> <td> <div align="left"> <%=rs(5)%></div></td> <td> <div align="left"> <%=rs(6)%></div></td> <td> <div align="left"> <%=rs(7)%></div></td> <td> <div align="left"> <%=rs(8)%></div></td> <td> <div align="left"> <%=rs(9)%></div></td> <td> <div align="left"> <%=rs(10)%></div></td> <td> <div align="left"> <%=rs(11)%></div></td> </tr> <% rs.movenext loop end if
rs.Close set rs = nothing conn.close set conn = nothing Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "content-disposition", "inline; filename=temp.xls" %> </table>
</body>
</html>
|