最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP利用FSO导出到CSV文件类技巧

日期:06-17    来源:中国设计秀    作者:cnwebshow.com

程序代码FEa中国设计秀

<%FEa中国设计秀
'==========================================================FEa中国设计秀
'将纪录输出为(.csv)文件FEa中国设计秀
'制作日期:2003年3月FEa中国设计秀
'作者         :塞北的雪FEa中国设计秀
'==========================================================FEa中国设计秀
Class Export_CSVFEa中国设计秀
   PRivate fso '文件系统对象FEa中国设计秀
   private fExportFEa中国设计秀
   dim Exp_Type  FEa中国设计秀

   private sub Class_Initialize()FEa中国设计秀
       set FSO= Server.CreateObject("Scripting.FileSystemObject")   '建立文件系统对象实例FEa中国设计秀
       Exp_Type=1   '导出类型  1为追加方式写入一个文件  2为新建一个新文件再写入FEa中国设计秀
   end subFEa中国设计秀
   FEa中国设计秀
   '关闭对象FEa中国设计秀
   private sub Class_Terminate()FEa中国设计秀
       fExport.CloseFEa中国设计秀
       set FSO=nothingFEa中国设计秀
   end subFEa中国设计秀
   FEa中国设计秀
   '导出主程序(用数组指定字段)FEa中国设计秀
   public Function ExportFile(fullpath,rsset, HeaderArray)FEa中国设计秀
        if Exp_type=1 thenFEa中国设计秀
             if not ExistFile(fullpath) thenFEa中国设计秀
                if CreateFile(fullpath) thenFEa中国设计秀
                   WriteHeader HeaderArrayFEa中国设计秀
                   WriteBody rsSet,HeaderArrayFEa中国设计秀
                elseFEa中国设计秀
                   err_Show "创建文件时发生错误!"FEa中国设计秀
                end ifFEa中国设计秀
             elseFEa中国设计秀
                 FEa中国设计秀
                if OpenFile(fullpath) thenFEa中国设计秀
                  WriteBody rsSet,HeaderArray                FEa中国设计秀
                elseFEa中国设计秀
                  err_Show "打开文件时发生错误!"                                   FEa中国设计秀
                end ifFEa中国设计秀
             end ifFEa中国设计秀
        elseif Exp_type=2 thenFEa中国设计秀
             if ExistFile(fullpath) thenFEa中国设计秀
                   err_Show "文件名冲突!"FEa中国设计秀
             elseFEa中国设计秀
                if CreateFile(fullpath) thenFEa中国设计秀
                   WriteHeader HeaderArray   FEa中国设计秀
                   WriteBody rsSet,HeaderArrayFEa中国设计秀
                elseFEa中国设计秀
                   err_Show "创建文件时发生错误!"                                   FEa中国设计秀
                end ifFEa中国设计秀
             end if     FEa中国设计秀
        end ifFEa中国设计秀
        if err=0 thenFEa中国设计秀
           ExportFile=trueFEa中国设计秀
        elseFEa中国设计秀
           ExportFile=falseFEa中国设计秀
        end ifFEa中国设计秀
   end functionFEa中国设计秀
   FEa中国设计秀
   '指定的标题书写FEa中国设计秀
   public sub WriteHeader( HeaderArray)FEa中国设计秀
         sLine = ""FEa中国设计秀
         for i=0 to ubound(HeaderArray,2)FEa中国设计秀
            sLine=sLine & "," & HeaderArray(0,i)FEa中国设计秀
         nextFEa中国设计秀
         if sLine<>"" then       FEa中国设计秀
            sLine=right(sLine,len(sLine)-1)FEa中国设计秀
            fExport.WriteLine(sLine)FEa中国设计秀
         end ifFEa中国设计秀
   end subFEa中国设计秀

'记录集指定的字段信息输出FEa中国设计秀
   public sub WriteBody(rsSet, HeaderArray)FEa中国设计秀
     rsSet.movefirstFEa中国设计秀
     Do Until rsSet.EOFFEa中国设计秀
       sLine = ""FEa中国设计秀
       for i=0 to ubound(HeaderArray,2)FEa中国设计秀
          sLine=sLine & "," & rsSet(HeaderArray(1,i))FEa中国设计秀
       nextFEa中国设计秀
      FEa中国设计秀
       if sLine <> "" thenFEa中国设计秀
         sLine = right(sLine, Len(sLine)-1)FEa中国设计秀
         fExport.WriteLine(sLine)FEa中国设计秀
       end if FEa中国设计秀
       rsSet.MoveNextFEa中国设计秀
     LoopFEa中国设计秀
   end subFEa中国设计秀
   FEa中国设计秀
   FEa中国设计秀
   '导出主程序(完全记录集)FEa中国设计秀
    public Function ExportFile2(fullpath,rsSet)FEa中国设计秀
        if Exp_type=1 thenFEa中国设计秀
             if not ExistFile(fullpath) thenFEa中国设计秀
                if CreateFile(fullpath) thenFEa中国设计秀
                   WriteHeader2 rsSetFEa中国设计秀
                   WriteBody2 rsSetFEa中国设计秀
                elseFEa中国设计秀
                   err_Show "创建文件时发生错误!"FEa中国设计秀
                end ifFEa中国设计秀
             elseFEa中国设计秀
                 FEa中国设计秀
                if OpenFile(fullpath) thenFEa中国设计秀
                  WriteBody2 rsSet                FEa中国设计秀
                elseFEa中国设计秀
                  err_Show "打开文件时发生错误!"                                   FEa中国设计秀
                end ifFEa中国设计秀
             end ifFEa中国设计秀
        elseif Exp_type=2 thenFEa中国设计秀
             if ExistFile(fullpath) thenFEa中国设计秀
                   err_Show "文件名冲突!"FEa中国设计秀
             elseFEa中国设计秀
                if CreateFile(fullpath) thenFEa中国设计秀
                   WriteHeader2 rsSet   FEa中国设计秀
                   WriteBody2 rsSetFEa中国设计秀
                elseFEa中国设计秀
                   err_Show "创建文件时发生错误!"                                   FEa中国设计秀
                end ifFEa中国设计秀
             end if     FEa中国设计秀
        end ifFEa中国设计秀
        if err=0 thenFEa中国设计秀
           ExportFile2=trueFEa中国设计秀
        elseFEa中国设计秀
           ExportFile2=falseFEa中国设计秀
        end ifFEa中国设计秀
   end functionFEa中国设计秀
   FEa中国设计秀
   '以字段名为标题书写FEa中国设计秀
   public sub WriteHeader2(rsSet)FEa中国设计秀
         sLine = ""FEa中国设计秀
         for i=0 to rsSet.fields.count-1FEa中国设计秀
            sLine=sLine & "," & rsSet.fields(i).nameFEa中国设计秀
         nextFEa中国设计秀
         if sLine<>"" then       FEa中国设计秀
            sLine=right(sLine,len(sLine)-1)FEa中国设计秀
            fExport.WriteLine(sLine)FEa中国设计秀
         end ifFEa中国设计秀
   end subFEa中国设计秀

'输出记录集中信息FEa中国设计秀
   public sub WriteBody2(rsSet)FEa中国设计秀
     rsSet.movefirstFEa中国设计秀
     Do Until rsSet.EOFFEa中国设计秀
       sLine = ""FEa中国设计秀
       for i=0 to rsSet.fields.count-1FEa中国设计秀
          sLine=sLine & "," & rsSet.fields(i).valueFEa中国设计秀
       nextFEa中国设计秀
      FEa中国设计秀
       if sLine <> "" thenFEa中国设计秀
         sLine = right(sLine, Len(sLine)-1)FEa中国设计秀
         fExport.WriteLine(sLine)FEa中国设计秀
       end if FEa中国设计秀
       rsSet.MoveNextFEa中国设计秀
     LoopFEa中国设计秀
   end subFEa中国设计秀
   FEa中国设计秀
   '输出错误信息FEa中国设计秀
   private sub Err_Show(errDesc)FEa中国设计秀
      Response.Write errDescFEa中国设计秀
      Response.End FEa中国设计秀
   end subFEa中国设计秀
   FEa中国设计秀
   '创建一个文件FEa中国设计秀
   public Function CreateFile(fullpath)FEa中国设计秀
        Set fExport = FSO.CreateTextFile(FullPath, false)FEa中国设计秀
        if err=0 thenFEa中国设计秀
           CreateFile=trueFEa中国设计秀
        elseFEa中国设计秀
           CreateFile=falseFEa中国设计秀
        end ifFEa中国设计秀
   end functionFEa中国设计秀
   FEa中国设计秀
   '打开一个文件FEa中国设计秀
   public Function OpenFile(fullpath)FEa中国设计秀
            set fExport=FSO.OpenTextFile(fullPath,8,false)FEa中国设计秀
            if err=0 thenFEa中国设计秀
               OpenFile=trueFEa中国设计秀
            elseFEa中国设计秀
              OpenFile=falseFEa中国设计秀
            end ifFEa中国设计秀
   end functionFEa中国设计秀
   FEa中国设计秀
   FEa中国设计秀
   '判断指定文件名的文件是否存在FEa中国设计秀
   public function ExistFile(fullpath)FEa中国设计秀
       if FSO.FileExists(fullpath) thenFEa中国设计秀
           ExistFile=trueFEa中国设计秀
       elseFEa中国设计秀
           ExistFile=falseFEa中国设计秀
       end if  FEa中国设计秀
   end functionFEa中国设计秀
      FEa中国设计秀
end ClassFEa中国设计秀
%>FEa中国设计秀
 FEa中国设计秀

本文引用地址:/bc/article_46239.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明