473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Exporting Datagrid to Excel (unable to read file)

Hi,
Is there anything wrong with the code below in sending my browser page to
Excel? Before my page opens in Excel there's a message "Problems came up in
the following areas during load:" and it shows a CSS file in the "temporary
internet files" path. But when i click OK the page displays beautifully.
Even though my page has 3 datagrids, they all display with the same style as
seen in the browser page.

Though, the second problem is, when i try to export a datagrid which has
many rows, it will not export at all and a popup "unable to read file"
displays and Excel just shows gray blankness. Here is the code that i'm am
using:

Public Shared Sub ExportToExcel(ByVal argDG As DataGrid, ByVal argPage
As Page)

Dim resp As HttpResponse
resp = argPage.Response
resp.ContentType = "application/download"
resp.AppendHeader("Content-Disposition",
"attachment;filename=GLdata.xls")
Dim colHeaders As String

Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

argDG.RenderControl(hw)

End Sub

Jun 20 '07 #1
3 5059
As far as the row count - I believe there is a limit of around 65,000 rows
for Excel - - how many rows need to be exported?

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"John Walker" <Jo********@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
Hi,
Is there anything wrong with the code below in sending my browser page to
Excel? Before my page opens in Excel there's a message "Problems came up
in
the following areas during load:" and it shows a CSS file in the
"temporary
internet files" path. But when i click OK the page displays beautifully.
Even though my page has 3 datagrids, they all display with the same style
as
seen in the browser page.

Though, the second problem is, when i try to export a datagrid which has
many rows, it will not export at all and a popup "unable to read file"
displays and Excel just shows gray blankness. Here is the code that i'm
am
using:

Public Shared Sub ExportToExcel(ByVal argDG As DataGrid, ByVal argPage
As Page)

Dim resp As HttpResponse
resp = argPage.Response
resp.ContentType = "application/download"
resp.AppendHeader("Content-Disposition",
"attachment;filename=GLdata.xls")
Dim colHeaders As String

Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

argDG.RenderControl(hw)

End Sub

Jun 20 '07 #2
check out this code sample at ASPNet101.com:
http://www.aspnet101.com/aspnet101/a...=ExportDGExcel

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"John Walker" <Jo********@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
Hi,
Is there anything wrong with the code below in sending my browser page to
Excel? Before my page opens in Excel there's a message "Problems came up
in
the following areas during load:" and it shows a CSS file in the
"temporary
internet files" path. But when i click OK the page displays beautifully.
Even though my page has 3 datagrids, they all display with the same style
as
seen in the browser page.

Though, the second problem is, when i try to export a datagrid which has
many rows, it will not export at all and a popup "unable to read file"
displays and Excel just shows gray blankness. Here is the code that i'm
am
using:

Public Shared Sub ExportToExcel(ByVal argDG As DataGrid, ByVal argPage
As Page)

Dim resp As HttpResponse
resp = argPage.Response
resp.ContentType = "application/download"
resp.AppendHeader("Content-Disposition",
"attachment;filename=GLdata.xls")
Dim colHeaders As String

Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

argDG.RenderControl(hw)

End Sub

Jun 20 '07 #3
Thank you! that helped - i wasnt setting EnableViewState to False, so that
solved my "unable to read file" problem.

But, i'm still getting the problem of a prompt window saying that it cant
find the CSS file... is there a way to not have it prompt? i dont care if it
cant find the CSS, i just dont want the user to have to click ok.

"David Wier" wrote:
check out this code sample at ASPNet101.com:
http://www.aspnet101.com/aspnet101/a...=ExportDGExcel

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"John Walker" <Jo********@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
Hi,
Is there anything wrong with the code below in sending my browser page to
Excel? Before my page opens in Excel there's a message "Problems came up
in
the following areas during load:" and it shows a CSS file in the
"temporary
internet files" path. But when i click OK the page displays beautifully.
Even though my page has 3 datagrids, they all display with the same style
as
seen in the browser page.

Though, the second problem is, when i try to export a datagrid which has
many rows, it will not export at all and a popup "unable to read file"
displays and Excel just shows gray blankness. Here is the code that i'm
am
using:

Public Shared Sub ExportToExcel(ByVal argDG As DataGrid, ByVal argPage
As Page)

Dim resp As HttpResponse
resp = argPage.Response
resp.ContentType = "application/download"
resp.AppendHeader("Content-Disposition",
"attachment;filename=GLdata.xls")
Dim colHeaders As String

Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

argDG.RenderControl(hw)

End Sub


Jun 20 '07 #4

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

Similar topics

2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
0
by: Steve Chatham | last post by:
I am stuck on this. It ought to be a simple reason as to why this is problematic, in that it works on smaller groups of data (say under 40 records), but doesn't on larger groups of records (40+)....
4
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
1
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw)...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
5
by: Matt Bailey | last post by:
Good afternoon, I have an asp.net project wherein I am trying to export data into excel. I have that working, however, I am typically dealing with a large volume of data when I do this. Can...
6
by: Coleen | last post by:
Hi All :-) I'm using .Net Framework 1.1, VB and need to be able to download the data from a datagrid into an Excel 2000 spreadsheet for our accounting users. Can anyone please point me to a good...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.