Connecting Tech Pros Worldwide Forums | Help | Site Map

Exporting Datagrid to Excel (unable to read file)

=?Utf-8?B?Sm9obiBXYWxrZXI=?=
Guest
 
Posts: n/a
#1: Jun 20 '07
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


David Wier
Guest
 
Posts: n/a
#2: Jun 20 '07

re: Exporting Datagrid to Excel (unable to read file)


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" <JohnWalker@discussions.microsoft.comwrote in message
news:F01CD8EE-61D4-4960-9566-86259F0E2AF5@microsoft.com...
Quote:
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
>

David Wier
Guest
 
Posts: n/a
#3: Jun 20 '07

re: Exporting Datagrid to Excel (unable to read file)


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" <JohnWalker@discussions.microsoft.comwrote in message
news:F01CD8EE-61D4-4960-9566-86259F0E2AF5@microsoft.com...
Quote:
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
>

=?Utf-8?B?Sm9obiBXYWxrZXI=?=
Guest
 
Posts: n/a
#4: Jun 20 '07

re: Exporting Datagrid to Excel (unable to read file)


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:
Quote:
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" <JohnWalker@discussions.microsoft.comwrote in message
news:F01CD8EE-61D4-4960-9566-86259F0E2AF5@microsoft.com...
Quote:
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
>
>
>
Closed Thread


Similar ASP.NET bytes