表格10000行,20多列。每个Cell都有数据(并不大)
全部生成Excel后,需要11分钟(包括简单的表格设置)我自己感觉比较慢,不知道大家的速度是多少??谢谢

解决方案 »

  1.   

    '将数据导入到excel worksheet中,先将数据保存在数组中,然后一次性导入worksheet,速度提高无数倍(没算过 :)
    'If the function run successfully then return true else return false
    'Parameter:
    'StartingCell: The position of the Starting cell
    'WriteHeader:if true, write the field name, else do not write itPrivate Function CopyRecords(RST As ADODB.Recordset, WS As Worksheet, _
        StartingCell As ExlCell, WriteHeader As Boolean) As Boolean
        
        Dim SomeArray() As Variant
        Dim Row         As Long
        Dim Col         As Long
        Dim Fd          As ADODB.Field
        Dim Recs        As Long 'Recordcount
        Dim iBeginRow   As Integer 'In SomeArray,the begin row of the real data,not header
        Dim Counter     As Integer, i As Integer
        
        On Error GoTo Err_CopyRecords    'check if recordset is opened
        If RST.State <> adStateOpen Then GoTo Err_CopyRecords
        ' check if recordset is not empty
        If RST.EOF And RST.BOF Then GoTo Err_CopyRecords
        RST.MoveLast
        ReDim SomeArray(0 To RST.RecordCount + 1, 0 To RST.Fields.Count)
        
        iBeginRow = 0
        
        If WriteHeader = True Then
        ' copy column headers to array
            Col = 0
            For Each Fd In RST.Fields
                SomeArray(0, Col) = Fd.Name
                Col = Col + 1
            Next
            iBeginRow = 1
        End If
        
        ' copy recordset to SomeArray
        RST.MoveFirst
        Recs = RST.RecordCount
        Counter = 0
        For Row = iBeginRow To Recs - 1 + iBeginRow
            Counter = Counter + 1
            If Counter <= Recs Then i = (Counter / Recs) * 100
            
            For Col = 0 To RST.Fields.Count - 1
                SomeArray(Row, Col) = RST.Fields(Col).Value
                If IsNull(SomeArray(Row, Col)) Then _
                SomeArray(Row, Col) = ""
            Next
            RST.MoveNext
        Next
        ' The range should have the same number of
        ' rows and cols as in the recordset
        WS.Range(WS.Cells(StartingCell.Row, StartingCell.Col), _
            WS.Cells(StartingCell.Row + RST.RecordCount + 1, _
            StartingCell.Col + RST.Fields.Count)).Value = SomeArray
        
    Exit_CopyRecords:    On Error GoTo 0
        CopyRecords = True
        Exit Function
        
    Err_CopyRecords:    CopyRecords = False
            
    End Function
      

  2.   

    Excel生成报表是比较慢,除非表格复杂,一般我觉得不用Excel为好
      

  3.   

    http://www.csdn.net/develop/read_article.asp?id=14952
      

  4.   

    http://www.csdn.net/develop/author/netauthor/lihonggen0/
      

  5.   

    tollers(哥呼拉) :
    记录集倒腾到数组,纯粹脱了裤子放屁。教你一个不用脱裤子的方法:
    oSheet.Range("A1").CopyFromRecordset rs