Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Export datagrid to Excel with a lot of rows

Reply
Thread Tools

Export datagrid to Excel with a lot of rows

 
 
Amirallia
Guest
Posts: n/a
 
      07-31-2006
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 ?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      07-31-2006
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 ?
>
>
>

 
Reply With Quote
 
 
 
 
Amirallia
Guest
Posts: n/a
 
      07-31-2006
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


 
Reply With Quote
 
imransyed63 imransyed63 is offline
Member
Join Date: May 2006
Posts: 31
 
 
Reply With Quote
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      07-31-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
>
>
>

 
Reply With Quote
 
Amirallia
Guest
Posts: n/a
 
      08-02-2006
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")


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export datagrid to Excel with a lot of rows bnob ASP .Net 2 07-31-2006 08:01 AM
Export datagrid with a lot of rows to Excel bnob ASP .Net Datagrid Control 0 07-28-2006 06:19 PM
how can I export ALL datagrid rows to excel? The Colonel ASP .Net 5 10-03-2005 05:40 PM
export ALL datagrid rows to excel (not just current page)? The Colonel ASP .Net 1 09-28-2005 08:54 PM
Export to excel data from Datagrid rows sunilkumar Reddy via DotNetMonster.com ASP .Net 0 06-27-2005 12:05 PM



Advertisments