<%
dim referer
referer = Request.ServerVariables("HTTP_REFERER")
Dim CName,action
action=request.Form("action")
CName="../../Excel/"
dim daytime
’daytime=year(now())&"-"&month(now())&"-"&day(now())&"-"&hour(now())&"-"&Minute(now())
daytime=year(now())&"年"&month(now())&"月"&day(now())&"日"&hour(now())&"時"
Set rs = Server.CreateObject("ADODB.Recordset")
’--從數(shù)據(jù)庫中把你想放到EXCEL中的數(shù)據(jù)查出來
sql="select * from gbook order by id desc"
rs.Open sql,conn
if rs.EOF and rs.BOF then
response.write "<script>alert(’操作出錯,下面是產生錯誤的可能原因:nn庫里暫時沒有數(shù)據(jù),所以不能導出EXCEL文件!’);location.href = ’"&referer&"’;</script>"
response.end
else
Dim Fs,Exc
Dim Excelstring,ExcelHead,Excelstr,Excelstr2
Dim Scou_FileNamen,Scou_FieldList
Dim Dest_FileName,Dest_FieldList
Dest_FileName=""&CName&""&daytime&".csv"
Excelstring = ""
ExcelHead = "識別號" & "," & "主題類型" & "," & "公司名稱"& "," & "姓名"& "," & "性別"& "," & "職位"& "," & "城市省份" & "," & "城市" & "," & "公司地址"& "," & "郵編"& "," & "郵件"& "," & "電話"& "," & "傳真" & "," & "手機"& "," & "公司網(wǎng)址"& "," & "詳細內容"& "," & "IP地址"& "," & "留言時間"
Set Rs = Server.CreateObject ("ADODB.Recordset")
Sql = "Select * From gbook"
Rs.Open Sql,Conn,1,3
Do While Not Rs.Eof
Excelstr = Rs("ID") & "," & Rs("zhutiname") & "," & Rs("gsname") & "," & Rs("gsname") & "," & Rs("sex") & "," & Rs("zhiwei")& "," & Rs("Province")& "," & Rs("City") & "," & Rs("dizhi") & "," & Rs("youbian") & "," & Rs("email") & "," & Rs("tel")& "," & Rs("fax")& "," & Rs("tel2") & "," & Rs("homeurl") & "," & Rs("body") & "," & Rs("ip") & "," & Rs("addtime")
Excelstr2 = Excelstr2 & Chr(13) & Excelstr
Rs.Movenext
Loop
Excelstring = ExcelHead & Excelstr2
Rs.Close
Set Rs=Nothing
Set Fs = CreateObject("Scripting.FileSystemObject")
Set Exc = Fs.OpenTextFile(Server.MapPath(Dest_FileName),2,True)
Exc.Write(Excelstring)
If Fs.FileExists(Server.MapPath(Dest_FileName)) Then
Response.Write("<a href=’"&Dest_FileName&"’>報表已經生成,點擊查看</a><hr>")
Response.Write("<a href=’"&referer&"’>返回</a>")
’Response.write(Excelstring)
Else
Response.Write("生成報表失。")
End If
end if
%> |