'strsql="select Code as 列1,ModuleCode as 列2 from SYS_Limit"
cmd.commandtext=strsql
RstRpt.CursorLocation = 3
set RstRpt=cmd.execute
If RstRpt.EOF Then
MyFile.WriteLine "没有得到可打印的数据。"
Else
Dim strContent
strContent = ""
'写表头
For Each x In RstRpt.Fields
strContent = strContent & x.Name & chr(9)
Next
MyFile.WriteLine strContent
While Not RstRpt.EOF
strContent = ""
For Each x In RstRpt.Fields
If IsNull(x.Value) Or IsEmpty(x.Value) Or x.Value = "" Then
strContent = strContent & " " & chr(9)
Else
strContent = strContent & x.Value & chr(9)
End If
Next
MyFile.WriteLine strContent
RstRpt.MoveNext
Wend
End If
MyFile.Close
'文件下在到客户端 2005-3-15
Server.ScriptTimeOut=15000
Response.Buffer=true
dim url,trueurl
trueurl=Server.MapPath(".\Excel") & "\" & strFileName
'response.Write trueurl
set objFso=server.CreateObject("scripting.filesystemobject")
set fn=objFso.GetFile(trueurl)
flsize=fn.size
flname=fn.name
set fn=nothing
set objFso=nothing
set objStream=server.CreateObject("adodb.stream")
objStream.Type=1
objStream.Open
objStream.LoadFromFile trueurl
response.clear() '清掉即可防止下载的文件出现乱码
select case lcase(right(flname,4))
case ".asf"
ContentType="video/x-ms-asf"
case ".avi"
ContentType="video/avi"
case ".doc"
ContentType="application/msword"
case ".zip"
ContentType="application/zip"
case ".xls"
ContentType="application/vnd.ms-excel"
case ".gif"
ContentType="image/gif"
case ".jpg","jpeg"
ContentType="image/jpeg"
case ".wav"
ContentType="audio/wav"
case ".mp3"
ContentType="audio/mpeg3"
case ".mpg", "mpeg"
ContentType="video/mpeg"
case ".rtf"
ContentType="application/rtf"
case ".htm","html"
ContentType="text/html"
case ".txt"
ContentType="text/plain"
Case ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
Response.Write "受保护文件,不能下载."
Response.End
case else
Response.ContentType="appliation/octet-stream"
end select
Response.AddHeader "Content-Disposition", "attachment; filename="&flname
Response.AddHeader "Content-Length", flsize
response.Expires = -1
Response.CharSet="UTF-8" '文件以什么格式存放
Response.ContentType=ContentType
while not objStream.EOS
Response.BinaryWrite objStream.Read(1024*64)
wend
objStream.Close
set objStream=nothing
Response.Flush
Response.end
'删除文件
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(Server.MapPath(".\Excel") & "\" & strFileName)=true then '判断要删除的文件是否存在
fso.DeleteFile Server.MapPath(".\Excel") & "\" & strFileName,true '删除该文件
end if
set fso=nothing