excel表格的导出

作者在 2007-04-14 21:25:00 发布以下内容

<!--#include file="conn.asp"-->
<head>
< http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
dim excelstring
dim excelstr
dim excelstr2
dim head
excelstring = ""
 head ="学号"& chr(9) & "姓名" & chr(9)& "年级"  & chr(9) & "电话" & Chr(9)& "生日"  & Chr(9) & "住址"
excel="creat"
If excel<>"" Then
     Set rs2 = Server.CreateObject ("ADODB.Recordset")
     sql2 = "Select * from _table"
     rs2.open sql2,conn,1,3
     do while not rs2.eof
     excelstr = rs2(1)& Chr(9) & rs2(2) & Chr(9) &rs2(3)& Chr(9) & rs2(4) & Chr(9) & rs2(5) & Chr(9) & rs2(6) & """"
     excelstr2 = excelstr2 & Chr(13) & excelstr
     rs2.movenext
     loop
     excelstring = head &Chr(13)& excelstr2
     'response.Write(excelstring)
     'rs2.close
     Set rs2=Nothing
     set fs = CreateObject("ing.FileSystemObject")
     set exc = fs.OpenTextFile(server.MapPath("excel.xls"),2,True)
     exc.write(excelstring)
     if fs.FileExists(Server.MapPath("excel.xls")) then
         Response.Write("<a href=excel.xls>报表已经生成,点击查看</a>")
         'Response.write(excelstring)
     else
         Response.Write("生成报表失败!")
     end if
End if%>
                                                                   
</body>
</html>

默认分类 | 阅读 1679 次
文章评论,共0条
游客请输入验证码
浏览15899次
最新评论