asp中使用Excel.Application无法生成excel,求高人帮忙!!
发布网友
发布时间:2023-12-21 07:43
我来回答
共1个回答
热心网友
时间:2024-04-01 00:01
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
'省略验证是否有管理员权限的语句
'欢迎围观:http://hi.baidu.com/helong72 ,这个代码是我生成通讯录用的
dim conn,strconn
strconn="driver={Microsoft Access driver (*.mdb)};dbq="&server.mappath("dataBase/DB#addressList.mdb") '这里改为你的数据库地址
set conn=server.CreateObject("adodb.connection")
conn.Open strconn
dim s,sql,filename,fs,myfile,x
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("excel.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
StartTime = Request("StartTime")
EndTime = Request("EndTime")
StartEndTime = "AddTime between #"& StartTime &" 00:00:00# and #"& EndTime &" 23:59:59#"
strSql = "select * from tAddressList"
Set rstData = DataToRsStatic(conn,strSql)
if not rstData.EOF and not rstData.BOF then
dim trLine,responsestr
strLine = "序 号" & chr(9) & "姓 名" & chr(9) & "电 话" & chr(9) & "Q Q" & chr(9) & "邮 箱" & chr(9) & "地 址" & chr(9) & "生 日" & chr(9) & "备 注"
'--将表的列名先写入EXCEL
myfile.writeline strLine
Do while Not rstData.EOF
strLine=""
strLine = rstData("fid") & chr(9) & rstData("fName")& chr(9) & rstData("fTel") & chr(9) & rstData("fQQ") & chr(9) & rstData("fEmail")& chr(9)&rstData("fAddress")& chr(9) &rstData("birthday")& chr(9) & rstData("fNote") & chr(9)& IfSendStr '括号改为你的数据库字段
myfile.writeline strLine
rstData.MoveNext
loop
end if
Response.Charset="utf-8"
Response.Write "<br><br>生成EXCEL文件成功,点击<a href=""excel.xls"" target=""_blank"">下载</a>!"
rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
Function DataToRsStatic(Conn,strSql)
Dim RsStatic
Set DataToRsStatic = Nothing
If Conn Is Nothing Then
Exit Function
End If
Set RsStatic = CreateObject("ADODB.RecordSet")
RsStatic.CursorLocation = 3
RsStatic.Open strSql,Conn,3,3
If Err.Number <> 0 Then
Exit Function
End If
Set DataToRsStatic = RsStatic
End Function
%>