Export Data From Web To Excel With More Performance

We are using a different framework, and I cannot use .NET GridView. We have a different Collection type and specialized grid.(Not inherit from .NET controls) I need to export data from web to MS-Excel. Here is the code.

   Me.Response.Clear()
   Me.Response.ContentEncoding = System.Text.Encoding.GetEncoding(1254)
   Me.Response.AddHeader("Content-Disposition", "Attachment;filename=Calls.xls")
   Me.Response.AddHeader("Content-type", "application/ms-excel")
            For n As Integer = 0 To Calls.Count - 1
                Me.Response.Write(Calls(n).ID & Chr(9))
                Me.Response.Write(Calls(n).ID & Chr(9))
                Me.Response.Write(Calls(n).DateCreated & Chr(9))
                Me.Response.Write(Calls(n).Employee.Name & Chr(9))
                Me.Response.Write(Calls(n).NetDurationInText & Chr(9))
                Me.Response.Write(Calls(n).Result.Name & Chr(9))
                Me.Response.Write(vbCrLf)
                If n Mod 50 = 0 Then
                    Me.Response.Flush()
                End If
            Next
    Me.Response.End()

But after the row count more than 2000-3000, website responses very slow. Despite I flush every 50 rows, it takes about 5 minutes for 2k-3k rows. I tried to flush every 100-200 row, also tried to write string directly to Response(I mean Response.Write("") ) When I debug, it loops and all time passes in "for loop".

Is there any better idea to export data faster than this way ?

Note: "Calls" is a collection that inherits from System.Collections.CollectionBase

Answers


If this is off just please comment and I will delete. I am C# so I might misunderstand. In your code it looks like you are building up the entire srtBl before you write it.

    For n As Integer = 0 To Calls.Count - 1
        Me.Response.Write(Calls(n).ID & Chr(9))
        Me.Response.Write(Calls(n).DateCreated & Chr(9))
        Me.Response.Write(Calls(n).Employee.Name & Chr(9))
        Me.Response.Write(Calls(n).Customer.Link.Name & Chr(9))
        Me.Response.Write(Calls(n).Vendor.Link.Name & Chr(9))
        Me.Response.Write(Calls(n).Result.Name & Chr(9))
        Me.Response.Write(vbCrLf)
        If n Mod 50 = 0 Then
            Me.Response.Flush()
        End If
    Next
    Me.Response.End()

I found the problem. It is related to my collection. I can say that this is the best way to export data to excel I have found.


Need Your Help

How to display NULL value as unchecked state in a TDBCheckBox descendant?

delphi delphi-6

Having a nullable dataset field of a boolean type, how to display its NULL value as an unchecked state in a TDBCheckBox control descendant linked to this field. By default, TDBCheckBox displays the...

issue with converting excel formula to java

java math

Hi i am new to java can anyone help me to convert this formula to java code?