<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-348  評論-598  文章-0  trackbacks-0
    因?yàn)轫?xiàng)目需要,所以從網(wǎng)上找了一個類,但是那個類問題比較多,所以自己修改了一下,增加容錯程度,提升一些性能,里面有部分代碼是根據(jù)我的項(xiàng)目修改的,所以大家在使用的時候自己改一下就可以了。

    使用方法:
    <%On Error Resume Next%>
    <!--#include file="../Include/Constants.Class.asp"-->
    <!--#include file="../Include/Config.Class.asp"-->
    <!--#include file="../Include/DBControl.Class.asp"-->
    <!--#include file="../Include/FunctionLib.Class.asp"-->
    <!--#include file="../Include/Manager.Class.asp"-->
    <!--#include file="../Include/Export2Excel.Class.asp"-->
    <%
    Dim Cfg,Db,Flib,Admin,Con,newExcel,url
    Set Cfg=New Config
    Set Con=New Constants
    Set Admin=New Manager
    Set Flib=New FunctionLib
    Set Db=New DBControl

    If session(request.QueryString("sql"))="" or session(request.QueryString("field"))="" Then
        Flib.MessageBox 
    "Excel導(dǎo)出頁面參數(shù)出錯!請聯(lián)系管理員","",0
    End If

    response.Write 
    "導(dǎo)出過程可能需要很長時間,請稍等<br>"
    response.Flush()
    set newExcel = New Export2Excel
    newExcel.FilePath 
    = "Excel/"
    newExcel.Sql 
    = session(request.QueryString("sql"))
    newExcel.Field 
    = session(request.QueryString("field"))
    response.write newExcel.export2Excel()


    %
    >

    類的源代碼:
    <%
    '  使用方法:
    '
      set newExcel = New Export2Excel
    '
      newExcel.FilePath = "/mail/excel/"----------------------------------路徑
    '
      newExcel.Sql = "select * from user"-------------------------------查詢語句
    '
      newExcel.Field = "帳號||姓名||所屬部門||"----------------------輸出列名
    '
      response.write newExcel.export2Excel()
    '
    類開始
    Class Export2Excel
    '聲明常量、變量
        Private strFilePath,strTitle,strSql,strField,strRows,strCols
        
    Private strCn,strHtml,strPath,strServerPath,Filename
        
    Private objDbCn,objRs
        
    Private objXlsApp,objXlsWorkBook,objXlsWorkSheet
        
    Private arrField
        
    '初始化類
        Private Sub Class_Initialize()
         
    set objDbCn = Db
         strTitle 
    = "查詢結(jié)果"
         strFilePath
    ="Excel/"
         strRows 
    = 2
         strCols 
    = 1
        
    End Sub
        
    '銷毀類
        Private Sub Class_Terminate()
        
    End Sub
        
    '屬性FilePath
        Public Property Let FilePath(value)
         strFilePath 
    = value
         strServerPath
    =strFilePath
        
    End Property
        
    Public Property Get FilePath()
         FilePath 
    = strFilePat
        
    End Property
        
    '屬性Title
        Public Property Let Title(value)
         strTitle 
    = value
        
    End Property
        
    Public Property Get Title()
         Title 
    = strTitle
        
    End Property
        
    '屬性Sql
        Public Property Let Sql(value)
         strSql 
    = value
        
    End Property
        
    Public Property Get Sql()
         Sql 
    = strSql
        
    End Property
        
    '屬性Field
        Public Property Let Field(value)
         strField 
    = value
        
    End Property
        
    Public Property Get Field()
         Field 
    = strField
        
    End Property
        
    '屬性Rows
        Public Property Let Rows(value)
         strRows 
    = value
        
    End Property
        
    Public Property Get Rows()
         Rows 
    = strRows
        
    End Property
        
    '屬性Cols
        Public Property Let Cols(value)
         strCols 
    = value
        
    End Property
        
    Public Property Get Cols()
         Cols 
    = strCols
        
    End Property
        
    '
        Public Function export2Excel()
         
    if strSql = "" or strField = "" then
          response.write 
    "參數(shù)設(shè)置錯誤,請與管理員聯(lián)系!謝謝"
          response.end
         
    end if
         
         strFilePath 
    = GetFilePath(Server.mappath(strFilePath&"upload.asp"),"\")
         
    set objFso = createobject("scripting.filesystemobject")
         
    if objFso.FolderExists(strFilePath) = False then
          objFso.Createfolder(strFilePath)
         
    end if
         Filename
    =cstr(createFileName()) & ".xls"
         strFileName 
    = strFilePath & Filename 
         objDbCn.Open()
         
    set objRs = objDbCn.execute(strSql)
         
    if objRs.EOF And objRs.BOF then
          strHtml 
    = "抱歉,暫時沒有任何合適的數(shù)據(jù)導(dǎo)出,如有疑問,請與管理員聯(lián)系!"
         
    else
          
    set objXlsApp = server.CreateObject("Excel.Application")
          objXlsApp.Visible 
    = false
          objXlsApp.WorkBooks.Add
          
    set objXlsWorkBook = objXlsApp.ActiveWorkBook
          
    set objXlsWorkSheet = objXlsWorkBook.WorkSheets(1)
          arrField 
    = split(strField,"||")
          
          
    for f = 0 to Ubound(arrField)
           objXlsWorkSheet.Cells(
    1,f+1).Value = arrField(f)
           
    'response.Write arrField(f)&" "
          next
          
    'response.Write "<br>"
          objRs=objRs.getRows()
          
    If instr(Sql,"exportEnterprise ")=0 then
              
    for c=0 to ubound(objRs,2)
                  
    If response.IsClientConnected=false then exit for '數(shù)據(jù)多導(dǎo)出時間很長,所以需要探測下客戶端是否還在連接
                  response.Write "正在導(dǎo)出第"&cstr(c+1)&"條<br>"
                response.Flush()
               
    for f = 0 to ubound(objRs,1)
                       
    If response.IsClientConnected=false then exit for
                 objXlsWorkSheet.Cells(c
    +2,f+1).Value = trim(Cstr(objRs(f,c)))&VBCR
                 
    'objXlsWorkSheet.Columns(f+1).ColumnWidth=Len(Cstr(objRs(f,c)))*2
               next
              
    next
              
          
    Else
                
    for c=0 to ubound(objRs,2)
                  
    If response.IsClientConnected=false then exit for
                  response.Write 
    "正在導(dǎo)出第"&cstr(c+1)&"條<br>"
                response.Flush()
               
    for f = 0 to ubound(objRs,1)
                   
    If response.IsClientConnected=false then exit for
                
    If f<>1 then
                 objXlsWorkSheet.Cells(c
    +2,f+1).Value = trim(Cstr(objRs(f,c)))&VBCR
                 
    'objXlsWorkSheet.Columns(f+1).ColumnWidth=Len(Cstr(objRs(f,c)))*2
                Else
                 objXlsWorkSheet.Cells(c
    +2,f+1).Value = trim(replace(replace(Cstr(objRs(f,c)),"0",""),"|"," "))&VBCR
                 
    'objXlsWorkSheet.Columns(f+1).ColumnWidth=Len(Cstr(objXlsWorkSheet.Cells(c+2,f+1).Value))*2            
                End If
               
    next
              
    next
          
    End If
          
          
    '必不可少,否則會出現(xiàn)錯誤
          If objFso.fileExists(strFileName)=true then
              objFso.deletefile strFileName
          
    End if
            response.Write 
    "導(dǎo)出成功!<br>"
            response.Flush()      
      
          objXlsWorkSheet.SaveAs strFileName
          
          strHtml 
    = "<script>location.href='" & GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")&strServerpath&Filename  & "';</script>"
          objXlsApp.Quit
    '重要
          set objXlsWorkSheet = nothing
          
    set objXlsWorkBook = nothing
          
    set objXlsApp = nothing
         
    end if
         objDbCn.Close()
         
    set objRs = nothing
         
    if err > 0 then
          strHtml 
    = "系統(tǒng)忙,請稍后重試"
         
    end if
         export2Excel 
    = strHtml
        
    End Function
        
    '函數(shù)
        Public Function createFileName()
         
    If Admin.id<>"" then
              fName
    =Admin.id
         
    Else
             fName
    =now
             fName
    =replace(fName,":","")
             fName
    =replace(fName,"-","")
             fName
    =replace(fName," ","")
         
    End If
         createFileName
    =fName
        
    End Function
            
        
    Public function GetFilePath(FullPath,str)
          
    If FullPath <> "" Then
            GetFilePath 
    = left(FullPath,InStrRev(FullPath, str))
            
    Else
            GetFilePath 
    = ""
          
    End If
        
    End function     
        
    'Public Function debug(varStr)
        ' response.write varStr
        ' response.end
        'End Function
        '類結(jié)束
    End Class
    %
    >



    ---------------------------------------------------------
    專注移動開發(fā)

    Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
    posted on 2007-07-29 16:28 TiGERTiAN 閱讀(2212) 評論(8)  編輯  收藏 所屬分類: VB/ASP

    評論:
    # re: asp導(dǎo)出excel用到的類[未登錄] 2008-09-17 10:41 | spring
    能發(fā)個源碼給我嗎,現(xiàn)在用的這些,<!--#include file="../Include/Constants.Class.asp"-->
    <!--#include file="../Include/Config.Class.asp"-->
    <!--#include file="../Include/DBControl.Class.asp"-->
    <!--#include file="../Include/FunctionLib.Class.asp"-->
    <!--#include file="../Include/Manager.Class.asp"-->沒有.E-MAIL:djj128@163.com  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2008-09-17 12:47 | TiGERTiAN
    @spring
    這些沒什么用的,類的代碼是全的。調(diào)用代碼就是:
    set newExcel = New Export2Excel
    newExcel.FilePath = "Excel/"
    newExcel.Sql = session(request.QueryString("sql"))
    newExcel.Field = session(request.QueryString("field"))
    response.write newExcel.export2Excel()
    其他沒有了。  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2008-10-21 23:34 | 不太冷
    If instr(Sql,"exportEnterprise ")=0 then
    exportEnterprise和Sql是什么地方的?我看不明白,把您的代碼運(yùn)行了下,不生成任何文件  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2008-10-21 23:56 | TiGERTiAN
    @不太冷
    這個條件語句是根據(jù)我自己的程序需要來的,可以把這個條件限制去掉,稍微修改下就好了  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2008-10-22 00:20 | 不太冷
    @TiGERTiAN
    不知道是否冒犯,我還在調(diào)試這個程序,可惜一直未能成功,你能加我QQ嗎?
    問幾個問題,1741821
      回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2009-02-11 14:45 | lzq
    太行了.  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2009-02-27 15:08 | asdfdg
    使用說明太不明確了,好多地方都要改的
    哪里連數(shù)據(jù)庫都不明確  回復(fù)  更多評論
      
    # re: asp導(dǎo)出excel用到的類 2009-06-11 14:27 | 站長
    很好用的站長查詢網(wǎng)站 http://www.ngiv.cn
    很全的技術(shù)論文 http://bbs.ngiv.cn  回復(fù)  更多評論
      
    主站蜘蛛池模板: 亚洲色成人网站WWW永久四虎 | 久久高潮一级毛片免费| 亚洲无吗在线视频| 亚洲av成人无码久久精品| 久久亚洲中文字幕精品一区| 永久免费无码网站在线观看| 亚洲免费综合色在线视频| 日韩免费人妻AV无码专区蜜桃| 亚洲天堂免费在线视频| 特黄特色大片免费| 亚洲av永久中文无码精品| 中文日韩亚洲欧美制服| 亚洲一区二区三区免费在线观看| 久久精品国产亚洲| 亚洲AV永久无码精品水牛影视| 亚洲综合图色40p| 亚洲色无码专区在线观看| 在线亚洲午夜理论AV大片| 亚洲午夜精品久久久久久浪潮| 亚洲av无码专区在线观看素人| 国产精品四虎在线观看免费| 四虎免费在线观看| 免费无码成人AV片在线在线播放| 免费精品人在线二线三线区别| 日本三级2019在线观看免费| 日韩版码免费福利视频| 免费无码又爽又刺激聊天APP| 最新中文字幕免费视频| 成人a免费α片在线视频网站| 免费黄网在线观看| 成人国产mv免费视频| 国产伦精品一区二区三区免费下载| 四虎永久在线精品视频免费观看| 免费女人18毛片a级毛片视频| 国产成人青青热久免费精品| 又黄又大又爽免费视频| 亚洲第一区在线观看| 国产亚洲?V无码?V男人的天堂 | 国产99视频精品免费视频7| 亚洲国产精品一区二区第一页免| 亚洲色偷拍区另类无码专区|