471,591 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,591 software developers and data experts.

Export datagrid to Excel with a lot of rows

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 ?
Jul 31 '06 #1
4 2073
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 ?
Jul 31 '06 #2
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
Jul 31 '06 #3
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
Jul 31 '06 #4
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")
Aug 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by sunilkumar Reddy via DotNetMonster.com | last post: by
1 post views Thread by Diego | last post: by
8 posts views Thread by DC Gringo | last post: by
reply views Thread by sunilkumar Reddy via DotNetMonster.com | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.