<% '歡迎與我交流和學(xué)習(xí) '作者:幸福的子彈 'blog:http://mysheji.com/blog 'e-mail:zhaojiangang@gmail.com 'qq:37294812 '----------------------------------------------------------------------------- '開(kāi)啟容錯(cuò)機(jī)制 on error resume next '功能,檢測(cè)服務(wù)器是否支持指定組件 function object_install(strclassstring) on error resume next object_install=false dim xtestobj set xtestobj=server.createobject(strclassstring) if -2147221005 <> err then object_install=true set xtestobj=nothing end function if object_install("scripting.filesystemobject")=false then response.write "<div style='color:#333;height:20px;line-height:20px;border:1px solid #ddcf8f;padding:6px;background:#ffffed;font-family:verdana'>對(duì)不起,您的空間不支持fso組件,請(qǐng)與管理員聯(lián)系!</div>" response.end end if if object_install("adodb.stream")=false then response.write "<div style='color:#333;height:20px;line-height:20px;border:1px solid #ddcf8f;padding:6px;background:#ffffed;font-family:verdana'>對(duì)不起,您的空間不支持adodb.stream功能,請(qǐng)與管理員聯(lián)系!</div>" response.end end if '----------------------------------------------------------------------------- '函數(shù)名稱:readtextfile '作用:利用adodb.stream對(duì)象來(lái)讀取文本文件 '參數(shù):fileurl文件相對(duì)路徑,filecharset:文件編碼 function readfromtextfile (fileurl,filecharset)'函數(shù) dim str set stm=server.createobject("adodb.stream") stm.type=2 '指定或返回的數(shù)據(jù)類型, stm.mode=3 '指定打開(kāi)模式,現(xiàn)在為可以讀寫(xiě)模式,類似于word的只讀或鎖定功能 stm.charset=filecharset stm.open stm.loadfromfile server.mappath(fileurl) str=stm.readtext readfromtextfile=str end function '----------------------------------------------------------------------------- '函數(shù)名稱:writetotextfile '作用:利用adodb.stream對(duì)象來(lái)寫(xiě)入文本文件 sub writetotextfile(fileurl,str,filecharset) '方法 set stm=server.createobject("adodb.stream") stm.type=2 stm.mode=3 stm.charset=filecharset stm.open stm.writetext str stm.savetofile server.mappath(fileurl),2 stm.flush end sub '----------------------------------------------------------------------------- '功能:自動(dòng)創(chuàng)建文件夾 '創(chuàng)建一級(jí)或多級(jí)目錄,可以創(chuàng)建不存在的根目錄 '參數(shù):要?jiǎng)?chuàng)建的目錄名稱,可以是多級(jí) '返回邏輯值,true成功,false失敗 '創(chuàng)建目錄的根目錄從當(dāng)前目錄開(kāi)始 function createmultifolder(byval cfolder) dim objfso,phcreatefolder,createfolderarray,createfolder dim i,ii,createfoldersub,phcreatefoldersub,blinfo blinfo = false createfolder = cfolder on error resume next set objfso = server.createobject("scripting.filesystemobject") if err then err.clear() exit function end if createfolder = replace(createfolder,"","/") if left(createfolder,1)="/" then createfolder = right(createfolder,len(createfolder)-1) end if if right(createfolder,1)="/" then createfolder = left(createfolder,len(createfolder)-1) end if createfolderarray = split(createfolder,"/") for i = 0 to ubound(createfolderarray) createfoldersub = "" for ii = 0 to i createfoldersub = createfoldersub & createfolderarray(ii) & "/" next phcreatefoldersub = server.mappath(createfoldersub) if not objfso.folderexists(phcreatefoldersub) then objfso.createfolder(phcreatefoldersub) end if next if err then err.clear() else blinfo = true end if createmultifolder = blinfo end function '點(diǎn)擊下載提示 function downloadfile(strfile) strfilename = server.mappath(strfile) response.buffer = true response.clear set s = server.createobject("adodb.stream") s.open s.type = 1 on error resume next set fso = server.createobject("scripting.filesystemobject") if not fso.fileexists(strfilename) then response.write("<h1>error:</h1>" & strfilename & " does not exist<p>") response.end end if set f = fso.getfile(strfilename) intfilelength = f.size s.loadfromfile(strfilename) if err then response.write("<h1>error: </h1>" & err.description & "<p>") response.end end if response.addheader "content-disposition", "attachment; filename=" & f.name response.addheader "content-length", intfilelength response.charset = "utf-8" response.contenttype = "application/octet-stream" response.binarywrite s.read response.flush s.close set s = nothing end function '----------------------------------------------------------------------------- if err then err.clear set conn = nothing response.write "<div style='color:#333;height:20px;line-height:20px;border:1px solid #ddcf8f;padding:6px;background:#ffffed;font-family:verdana'>網(wǎng)站異常出錯(cuò),請(qǐng)與管理員聯(lián)系,謝謝!</div>" response.end end if %>
<% on error resume next dim db_path,conn,connstr db_path = "data/data.mdb" set conn= server.createobject("adodb.connection") connstr = "provider=microsoft.jet.oledb.4.0;data source="&server.mappath(db_path) on error resume next conn.open connstr if err then err.clear set conn = nothing response.write "<script language=javascript> location.href='error.asp?msg=系統(tǒng)出錯(cuò),請(qǐng)聯(lián)系管理員!' </script>" response.end end if set rs=server.createobject("adodb.recordset") rs.open "select * from m_ss",conn,1,1 s=rs("s_main") all=split(s,"|||") for i=0 to 20 next if not (rs.eof and rs.bof) then dim ttxt,file,filepath,writefile ttxt="jb.csv" '為要寫(xiě)入的文件取個(gè)文件名,后綴可以是txt,xls,這里我用csv,這種文件打開(kāi)也是excel表 set file = createobject("scripting.filesystemobject") application.lock '寫(xiě)入文件的存放路徑,一定要開(kāi)放這個(gè)路徑下的讀寫(xiě)權(quán)限 filepath=server.mappath(ttxt) set writefile = file.createtextfile(filepath,true) '在表格中寫(xiě)入第一行,字段描述,這個(gè)根據(jù)你實(shí)際的數(shù)據(jù)表字段來(lái)寫(xiě) writefile.writeline "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak" do while not rs.eof writefile.writeline rs("s_id")&","&rs("s_no")&","&rs("s_top")&","&rs("s_title")&","&rs("s_name")&","&rs("s_add")&","&rs("s_ajlx")&","&rs("s_fy1")&","&rs("s_fy2")&","&rs("s_fy3")&","&rs("s_fg1")&","&rs("s_fg2")&","&rs("s_fg3")&","&rs("s_yg")&","&rs("s_bg")&","&all(0)&","&all(1)&","&all(2)&","&all(3)&","&all(4)&","&all(5)&","&all(6)&","&all(7)&","&all(8)&","&all(9)&","&all(10)&","&all(11)&","&all(12)&","&all(13)&","&all(14)&","&all(15)&","&all(16)&","&all(17)&","&all(18)&","&all(19)&","&rs("s_ly")&","&rs("s_bz")&","&rs("s_sfz")&","&rs("s_time") rs.movenext loop '以上三行作用是逐行將數(shù)據(jù)寫(xiě)入表中 writefile.close application.unlock rs.close set rs=nothing end if rs.close set rs=nothing response.write "數(shù)據(jù)導(dǎo)出成功!" response.end %>