用asp生成excel...

 

今天用asp生成Excel。。。贴一下代码,以后可以参考参考。。

<!--#include file="conn.asp"-->
<HTML>
<HEAD>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<a href="?act=make">在线生成EXCEL</a>
<hr size=1 align=left width=300px>
<%
if Request("act") = "" then
else
dim rs,sql,filename,fs,myfile,x
Set fs = server.CreateObject("scripting.filesystemobject")
filename = Server.MapPath("online.xls")
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select identity(int,1,1) '编号', y.bm '部门',y.yg_name '用户',y.zhiwu '职务',y.contact_phone '电话',y.contact_tel '手机' into linshi from zl_yuangong y where y.bm  in(select fullname from zl_bm where pre_id=8) and y.zg>=1 and (islizhi is null or islizhi=0) group by y.bm ,y.yg_name ,y.zhiwu ,y.contact_phone ,y.contact_tel"
conn.execute sql
sql = "select * from linshi"
rs.Open sql,conn,1,1

if rs.EOF and rs.BOF then
else
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine = strLine & trim(x.name) & chr(9)
Next
myfile.writeline strLine
Do while Not rs.EOF


strLine=""
for each x in rs.Fields
strLine = strLine & trim(x.value) & chr(9)
next
myfile.writeline strLine
rs.MoveNext
loop
end if
rs.Close
set rs = nothing
Response.Write "生成EXCEL文件成功!下载:<a href=""online.xls"">在线生成EXCEL</a> "
sql = "drop table linshi"
conn.execute sql
End If

%>

</HTML>

你可能感兴趣的:(用asp生成excel...)