Response.Write fails to provide client with large Excel report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hksl
    New Member
    • Feb 2013
    • 2

    #1

    Response.Write fails to provide client with large Excel report

    I am new to the whole issue of generating/sending Excel report in ASP.net. Code below sometimes does not work for large amount of data (large Excel report). Client has IE9 and MS Office 2010. Client does not get any errors, client simply does not get report after long wait time. Are there any alternative to the approach below, for providing client with large Excel report ? Anything done wrong in the code below that may cause the problem. All replies are appreciated.
    Code:
    Response.ContentType = "application/ms-excel"
    Response.AddHeader("Content-Disposition", "attachment; filename=" + ReportName + ".xls")
    
    Response.Write("<table border =1>")
    For Each ch As ColumnHeaders In arrCh
    	If ch.ColumnName <> "" Then
            	pCh = pCh & "<td><b>" & ch.ColumnName & "</b></td>"
                        pColCount = pColCount + 1
                    End If
    Next
               
    If pExtraHeader <> "" Then
    	Response.Write(pExtraHeader)
    End If
    Response.Write("<tr>" & pCh & "</tr>")
    If oSQLDataReader.HasRows Then
    	Do While oSQLDataReader.Read()
            	Response.Write("<tr>")
                    For I = 0 To arrCh.Count - 1
                        If arrCh(I + 1).columnname <> "" Then
                            Response.Write("<td>" & strColumnValue & "</td>")
                            If arrCh.Item(I + 1).isTotal = True Then
                                arrCh.Item(I + 1).placeholder = CDbl(arrCh.Item(I + 1).placeholder) + CDbl(oSQLDataReader.GetValue(I))
                            End If
                         End If
                    Next
                    Response.Write("</tr>")
            Loop
    
            Dim pTotal As String = ""
            For Each ch As ColumnHeaders In arrCh
          	  If ch.ColumnName <> "" Then
            	  pTotal = pTotal & "<td><b>" & strColumnValue & "</b></td>"
              End If
            Next
    	Response.Write("<tr>" & pTotal & "</tr>"
    
    End If
    Response.Write("</table>")
    Last edited by Rabbit; Feb 5 '13, 05:04 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It works with small reports though? And how big are we talking?

    Comment

    • hksl
      New Member
      • Feb 2013
      • 2

      #3
      I have no direct contact with client, but I was told 6 MB. Though when I retrieve same report connecting from my system, get ope or save prompt, and save, xls file size is 281 KB. Assumption is that size of HTML sent bt Response.Write is too big. I am trying to find way to decrease size of HTML that is sent using Response.Write or should I use something else instead of Response.Write?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Have you considered binding the data source to a GridView?
        Or using a Repeater to display the data?

        You could consider implementing pagination in your GridView or Repeater to reduce the amount of data being rendered at a given time.

        -Frinny

        Comment

        Working...