Export datagrid to Excel with a lot of rows

Discussion in 'ASP .Net' started by Amirallia, Jul 31, 2006.

  1. Amirallia

    Amirallia Guest

    Hello

    Here's my code to export a datagrid to Exel :
    Response.Clear()
    Response.Buffer = True
    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Dim monStringWriter As StringWriter = New StringWriter
    Dim monHtmlTextWriter As HtmlTextWriter = New
    HtmlTextWriter(monStringWriter)
    monDG.RenderControl(monHtmlTextWriter)
    Response.Write(monStringWriter.ToString())
    Response.End()

    It's work perfectly, but when my datagrid displays for exeample 10000
    rows,
    the export doesn't work.
    Instead I have the page impossible to display !!!!

    Any idea ?
     
    Amirallia, Jul 31, 2006
    #1
    1. Advertising

  2. You could write it out to disk and then redirect to it, providing the
    directory the file is written to is a virtual one.


    --
    -Demetri


    "Amirallia" wrote:

    > Hello
    >
    > Here's my code to export a datagrid to Exel :
    > Response.Clear()
    > Response.Buffer = True
    > Response.ContentType = "application/vnd.ms-excel"
    > Response.Charset = ""
    > Dim monStringWriter As StringWriter = New StringWriter
    > Dim monHtmlTextWriter As HtmlTextWriter = New
    > HtmlTextWriter(monStringWriter)
    > monDG.RenderControl(monHtmlTextWriter)
    > Response.Write(monStringWriter.ToString())
    > Response.End()
    >
    > It's work perfectly, but when my datagrid displays for exeample 10000
    > rows,
    > the export doesn't work.
    > Instead I have the page impossible to display !!!!
    >
    > Any idea ?
    >
    >
    >
     
    =?Utf-8?B?RGVtZXRyaQ==?=, Jul 31, 2006
    #2
    1. Advertising

  3. Amirallia

    Amirallia Guest

    Demetri a formulé la demande :
    > You could write it out to disk and then redirect to it, providing the
    > directory the file is written to is a virtual one.
    >
    >
    > --
    > -Demetri
    >
    >
    > "Amirallia" wrote:
    >
    >> Hello
    >>
    >> Here's my code to export a datagrid to Exel :
    >> Response.Clear()
    >> Response.Buffer = True
    >> Response.ContentType = "application/vnd.ms-excel"
    >> Response.Charset = ""
    >> Dim monStringWriter As StringWriter = New StringWriter
    >> Dim monHtmlTextWriter As HtmlTextWriter = New
    >> HtmlTextWriter(monStringWriter)
    >> monDG.RenderControl(monHtmlTextWriter)
    >> Response.Write(monStringWriter.ToString())
    >> Response.End()
    >>
    >> It's work perfectly, but when my datagrid displays for exeample 10000
    >> rows,
    >> the export doesn't work.
    >> Instead I have the page impossible to display !!!!
    >>
    >> Any idea ?
    >>
    >>
    >>


    Do you have an example ?

    Thanks
     
    Amirallia, Jul 31, 2006
    #3
  4. Amirallia

    imransyed63

    Joined:
    May 16, 2006
    Messages:
    27
  5. No tangible example but its not that hard.

    You have a web folder setup where the file will be written out to. Make sure
    permissions are setup for ASPNet User to write out the files there.

    Your method that extracts the data from the grid then converts that data to
    an excel format (most common is CSV) and then outputs it to a file in the web
    folder mentioned above.

    Then at the end of that method it does a Redirect to that file.

    --
    -Demetri


    "Amirallia" wrote:

    > Demetri a formulé la demande :
    > > You could write it out to disk and then redirect to it, providing the
    > > directory the file is written to is a virtual one.
    > >
    > >
    > > --
    > > -Demetri
    > >
    > >
    > > "Amirallia" wrote:
    > >
    > >> Hello
    > >>
    > >> Here's my code to export a datagrid to Exel :
    > >> Response.Clear()
    > >> Response.Buffer = True
    > >> Response.ContentType = "application/vnd.ms-excel"
    > >> Response.Charset = ""
    > >> Dim monStringWriter As StringWriter = New StringWriter
    > >> Dim monHtmlTextWriter As HtmlTextWriter = New
    > >> HtmlTextWriter(monStringWriter)
    > >> monDG.RenderControl(monHtmlTextWriter)
    > >> Response.Write(monStringWriter.ToString())
    > >> Response.End()
    > >>
    > >> It's work perfectly, but when my datagrid displays for exeample 10000
    > >> rows,
    > >> the export doesn't work.
    > >> Instead I have the page impossible to display !!!!
    > >>
    > >> Any idea ?
    > >>
    > >>
    > >>

    >
    > Do you have an example ?
    >
    > Thanks
    >
    >
    >
     
    =?Utf-8?B?RGVtZXRyaQ==?=, Jul 31, 2006
    #5
  6. Amirallia

    Amirallia Guest

    Demetri avait écrit le 31.07.2006 :
    > No tangible example but its not that hard.
    >
    > You have a web folder setup where the file will be written out to. Make sure
    > permissions are setup for ASPNet User to write out the files there.
    >
    > Your method that extracts the data from the grid then converts that data to
    > an excel format (most common is CSV) and then outputs it to a file in the web
    > folder mentioned above.
    >
    > Then at the end of that method it does a Redirect to that file.
    >
    > --
    > -Demetri
    >
    >
    > "Amirallia" wrote:
    >
    >> Demetri a formulé la demande :
    >>> You could write it out to disk and then redirect to it, providing the
    >>> directory the file is written to is a virtual one.
    >>>
    >>>
    >>> --
    >>> -Demetri
    >>>
    >>>
    >>> "Amirallia" wrote:
    >>>
    >>>> Hello
    >>>>
    >>>> Here's my code to export a datagrid to Exel :
    >>>> Response.Clear()
    >>>> Response.Buffer = True
    >>>> Response.ContentType = "application/vnd.ms-excel"
    >>>> Response.Charset = ""
    >>>> Dim monStringWriter As StringWriter = New StringWriter
    >>>> Dim monHtmlTextWriter As HtmlTextWriter = New
    >>>> HtmlTextWriter(monStringWriter)
    >>>> monDG.RenderControl(monHtmlTextWriter)
    >>>> Response.Write(monStringWriter.ToString())
    >>>> Response.End()
    >>>>
    >>>> It's work perfectly, but when my datagrid displays for exeample 10000
    >>>> rows,
    >>>> the export doesn't work.
    >>>> Instead I have the page impossible to display !!!!
    >>>>
    >>>> Any idea ?
    >>>>
    >>>>
    >>>>

    >>
    >> Do you have an example ?
    >>
    >> Thanks
    >>
    >>
    >>


    sorry but it makes the same thing, directly redirect to a white page.

    If I put a break point in my code, when I click on the button, It'
    doesn't stop... Here'is my code

    Dim Separator As String = ";"
    Dim lLigne, lCol As Integer
    Dim item As DataGridColumn
    Dim strValeur As String
    Dim monStreamWriter As System.IO.StreamWriter = New
    System.IO.StreamWriter(Server.MapPath("./") & "upload\xxx.csv")

    Try
    For Each item In dg.Columns
    monStreamWriter.WriteLine(item.HeaderText & Separator)
    Next item

    monStreamWriter.WriteLine(ControlChars.NewLine)
    For lLigne = 1 To Me.dg.Items.Count - 1
    For lCol = 0 To Me.dg.Items(lLigne).Cells.Count - 1
    If Me.dg.Items(lLigne).Cells(lCol).Text = " "
    Then
    strValeur = ""
    Else
    strValeur =
    Me.dg.Items(lLigne).Cells(lCol).Text
    End If
    strValeur = strValeur & Separator
    Next

    monStreamWriter.WriteLine(strValeur & Separator)
    monStreamWriter.WriteLine(ControlChars.NewLine)
    Next

    monStreamWriter.Close()

    Response.Redirect("Upload\xxx.csv")
     
    Amirallia, Aug 2, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunilkumar Reddy via DotNetMonster.com

    Export to excel data from Datagrid rows

    sunilkumar Reddy via DotNetMonster.com, Jun 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    657
    sunilkumar Reddy via DotNetMonster.com
    Jun 27, 2005
  2. The Colonel
    Replies:
    1
    Views:
    461
    The Colonel
    Sep 28, 2005
  3. The Colonel
    Replies:
    5
    Views:
    1,436
    The Colonel
    Oct 3, 2005
  4. bnob
    Replies:
    2
    Views:
    466
    Amirallia
    Jul 31, 2006
  5. bnob

    Export datagrid with a lot of rows to Excel

    bnob, Jul 28, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    123
Loading...

Share This Page