1个回答
展开全部
<%
conn="driver={SQL SERVER};Server=(local);UID=sa;PWD=11111111;database=table_name"
Set rs = Server.CreateObject("ADODB.RecordSet")
sqlstr="你的查询语句"
rs.open sqlstr,conn,1,3
%>
导出文件如下:
<%Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename="log.xls"
temp=filename
filename=Request.ServerVariables("APPL_PHYSICAL_PATH")&"\"+filename
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine
while not rs.eof
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine
rs.movenext
wend
link="<A HREF=\" & temp & ">请点击下载excel文件</a>"
Response.write link
set myfile = nothing
Set fs=Nothing
rs.close
%>
conn="driver={SQL SERVER};Server=(local);UID=sa;PWD=11111111;database=table_name"
Set rs = Server.CreateObject("ADODB.RecordSet")
sqlstr="你的查询语句"
rs.open sqlstr,conn,1,3
%>
导出文件如下:
<%Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename="log.xls"
temp=filename
filename=Request.ServerVariables("APPL_PHYSICAL_PATH")&"\"+filename
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine
while not rs.eof
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine
rs.movenext
wend
link="<A HREF=\" & temp & ">请点击下载excel文件</a>"
Response.write link
set myfile = nothing
Set fs=Nothing
rs.close
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询