日期:2014-05-17 浏览次数:21005 次
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>export</title> </head> <!--#include file="../Include/Const.asp" --> <!--#include file="../Include/ConnSiteData.asp" --> <body> <% '设置页面时间 Server.ScriptTimeOut=999999 dim s,sql,filename,fs,myfile,x,mFileName,ObjExcel,ObjSheet Set fs = server.CreateObject("scripting.filesystemobject") filename = Server.MapPath("contact.csv") '--如果原来的EXCEL文件存在的话删除它 if fs.FileExists(filename) then fs.DeleteFile(filename) end if '--创建csv文件 set myfile = fs.CreateTextFile(filename,true) '--从数据库中把你想放到csv中的数据查出来 strSql = "select * from Ameav_Contact order by OrgName asc" '--显示执行的SQL语句 Response.Write "<div id='sql'><strong>SQL 语句:</strong><br />"&strSql&"</div>" Set Rs =conn.execute(strSql) if not Rs.EOF and not Rs.BOF then dim trLine,responsestr strLine="" For each x in Rs.fields strLine = "OrgName,DepName,StaffName,Office,SubPhone,DirecPhone,Telephone,PersonEmail,CompanyEmail,Password,Remark"'Public,Password,Remark" Next myfile.writeline strLine Response.Write "<div id='data'>" Do while Not Rs.EOF strLine="" strLine= Rs("OrgName")&"," & Rs("DepName")&"," & Rs("StaffName") & "," & Rs("Office") & "," & Rs("SubPhone") & "," & Rs("DirecPhone") & "," & Rs("Telephone") & "," & Rs("PersonEmail") & "," & Rs("CompanyEmail") & "," & Rs("Password") & "," & Rs("Remark")'& Rs("Public") & "," & Rs("Password") & "," & Rs("Remark") if WriteDB=True then Response.Write strLine & "<br /><hr />" end if myfile.writeline strLine Rs.MoveNext loop Response.Write "</div>" end if Response.Write "<div id='down'><p><a href=""contact.csv"" target=""_blank"">生成文件成功,点击下载!</a></p></div>" Rs.Close :set Rs = nothing Conn.Close:Set Conn = nothing %> </body> </html>