如何将数据库中的数据转换为execel(用asp语言)
如何将数据库中的数据转换为execel(用asp语言)
给楼主一个参考例子
<!--#include file="../inc/conn.asp"-->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<%
sql =Request("sql") '得到搜索的sql语句
Response.Write(sql)
%>
<%
dim rs,sql,filename,fs,myfile,x,link
Set fs = server.CreateObject("scripting.filesystemobject")
filename = Server.MapPath ("../online1.xls") '生成的excel文件名和路径
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
Set rs = Server.CreateObject("ADODB.Recordset")
//sql = "select * from guest where g_result='空号,错号'"
rs.Open sql,conn
if rs.EOF and rs.BOF then
else
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next
myfile.writeline strLine
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
myfile.writeline strLine
rs.MoveNext
loop
end if
rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing
%>
<br>
<a href="javascript:history.go(-1)">返回</a>
<a href="../online1.xls">下载</a>
</BODY>
</HTML>