19
2018
03

asp导出excel文件

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%

Session.CodePage=936  

Response.Charset = "gb2312"  

%>

<!--#include file="conn.asp"-->

<%

set rs=server.CreateObject("adodb.recordset")

sql="Select userName,hyname From [hy]"

rs.open sql,conn,1,1

If Not Rs.Eof Then

        Html = "<table border='1'><tr><td>UserName</td><td>hyname</td></tr>"

While Not Rs.Eof 

   Html  = Html&"<tr><td>"&Rs(0)&"</td><td>"&Rs(1)&"</td></tr>"

Rs.MoveNext

Wend

Html  = Html&"</table>"

Response.Buffer=True

        Response.ContentType="application/excel"

        Response.AddHeader"Content-Disposition","attachment;filename=User_data_"&date()&".xls"

Response.Write(Html)

    Else

  Response.Write("<script>alert('未查询到数据!');location.href='./'</script>")

End If

Response.End()

%>


« 上一篇下一篇 »