高分求asp+acess如何导出并下载exxel文件
高分求asp+acess如何导出并下载exxel文件,主要能导出和下载就可以了 问题点数:0、回复次数:1Top
1 楼arrowy(清云卷浪)回复于 2005-04-01 12:04:07 得分 0
导出页:
<%
' ------------------------------数据库连接--------------------------
dim conn ,rs
set conn = ...
' ------------------------------数据导出函数------------------------
function XXX()
'写你要导出的
end function
'-------------------------------表头信息----------------------------
Dim ObjFso,XlsPath,StrLine,StrLine02,ResponseStr
Set ObjFso = Server.CreateObject("Scripting.FileSystemObject")
Fname = ProjectName & "_表名_" & Date() & ".xls"
XlsPath = Server.MapPath(Fname)
StrLine=""
If ObjFso.FileExists(XlsPath) Then
ObjFso.DeleteFile(XlsPath)
End If
'--创建EXCEL文件
Set NewFile = ObjFso.CreateTextFile(XlsPath,true)
StrLine = "XX表"
NewFile.WriteLine StrLine
StrLine = "名称: " & ProjectName
NewFile.WriteLine StrLine
StrLine = "信息I: " & Pm
NewFile.WriteLine StrLine
StrLine = "信息II: " & Cm
NewFile.WriteLine StrLine
StrLine = "信息III: (万元)"
NewFile.WriteLine StrLine
StrLine = "编 号" & chr(9) & "人员" & chr(9) & "字段名I" & chr(9) & "字段名II" & chr(9) & "字段名III" & chr(9) & "字段名IV" & chr(9) & chr(9) & "字段名V"
NewFile.WriteLine StrLine
StrLine = " " & chr(9) & " " & chr(9) & " " & chr(9) & " " & chr(9) & " " & chr(9) & "字段名VI" & chr(9) & "字段名VII" & chr(9) & " "
NewFile.WriteLine StrLine
' ================================
' 这里写你的从ACCESS导出数据的函数(顺序什么的要按上面字段顺序)
' ================================
conn.close
set conn=nothing
Set NewFile = Nothing
Set ObjFso = Nothing
Response.Redirect("testDownLoad.asp?fp=" & Fname)
%>
下载页 TestDownLoad.asp:
<%
' ///////////////////////////////////////////////////////
' 下载操作
'
' 输入参数:
' fp -> 文件链接地址
' ///////////////////////////////////////////////////////
Response.Buffer = true
Response.Clear
Dim FilePath,url
Dim fso,fl,flsize
Dim Dname
Dim objStream,ContentType,flName,isre,url1
'*********************************************调用时传入的下载文件名
Dname=Trim(request("fp"))
'******************************************************************
If Dname<>"" Then
'******************************下载文件存放的服务端目录
url = Dname
'***************************************************
End If
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
flName=fl.name
Set fl=Nothing
Set fso=Nothing
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile url
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 ".rar"
ContentType = "application/octet-stream"
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 ".mdb"
ContentType = "application/msaccess"
Case Else
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & flName
Response.AddHeader "Content-Length", flsize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
Response.Clear()
objStream.Close
Set objStream = Nothing
%>
Top




