473,666 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWriter( monStringWriter )
monDG.RenderCon trol(monHtmlTex tWriter)
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 2192
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.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWriter( monStringWriter )
monDG.RenderCon trol(monHtmlTex tWriter)
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.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWriter (monStringWrite r)
monDG.RenderCon trol(monHtmlTex tWriter)
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.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWriter( monStringWriter )
monDG.RenderCon trol(monHtmlTex tWriter)
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.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWrit er(monStringWri ter)
monDG.RenderCon trol(monHtmlTex tWriter)
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.Strea mWriter = New
System.IO.Strea mWriter(Server. MapPath("./") & "upload\xxx.csv ")

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

monStreamWriter .WriteLine(Cont rolChars.NewLin e)
For lLigne = 1 To Me.dg.Items.Cou nt - 1
For lCol = 0 To Me.dg.Items(lLi gne).Cells.Coun t - 1
If Me.dg.Items(lLi gne).Cells(lCol ).Text = " "
Then
strValeur = ""
Else
strValeur =
Me.dg.Items(lLi gne).Cells(lCol ).Text
End If
strValeur = strValeur & Separator
Next

monStreamWriter .WriteLine(strV aleur & Separator)
monStreamWriter .WriteLine(Cont rolChars.NewLin e)
Next

monStreamWriter .Close()

Response.Redire ct("Upload\xxx. csv")
Aug 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3762
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
0
1429
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we can take binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain sheet1 grid row2 data contain sheet2 grid row3 data contain sheet3 we have pressing one button ultrawebgrid (or) datagrid rows data to export
1
403
by: Diego | last post by:
Hi, I have a ASP.NET application and i'm interested in reporting in excel format. I read a good artile written by Steve C. Orr that gave me info about exporting to excel. http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp Basically the app shows the report in a datagrid and on the OnClick event of
8
2842
by: DC Gringo | last post by:
I have a simple button that should open another window and export a datagrid to an Excel file. I'm getting: "Name 'window' is not declared." What do I need to declare or import? <INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button" VALUE="Export to Excel"> Sub Button5_Click()
3
1662
by: mattdaddym | last post by:
Hi all, I have been using the following code to export my datagrids to excel for quite some time. Very simple and very effective. <code> Sub btnExcelExport_Click ( s As Object, e As EventArgs ) Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
0
1734
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain sheet1 grid row2 data contain sheet2 grid row3 data contain sheet3 we have pressing one button ultrawebgrid (or) datagrid rows data to export
0
2918
by: kieran | last post by:
Hi, I have an 'export to excel' button on my Datagrid. All works well except that on my Datagrid, I have sub total rows. The subtotal rows use colspan so that the subtotals are given above certain columns When I export to excel, I do not have the colspan. As a result, the subtotals appear over the wrong columns in Excel.
2
1768
by: leena13 | last post by:
Hi, The number of rows in the datagrid on my page are approx. around 14130. When I click on the button that exports the records to excel sheet, the page goes blank (I observed that none of the events are firing). To confirm this is happening because of the no. of rows, I modified the SP to retrieve around only 100 records. I could export these records in the datagrid successfully. I am aware that the max no of rows to export to excel...
2
6407
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the method.... it creates 6 sheets # region Namespaces using System;
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.