By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,965 Members | 1,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,965 IT Pros & Developers. It's quick & easy.

Datagrid --> Excel Spreadsheet - A "small detail" question

P: n/a
In a VB.NET application, I have a datagrid that I export to an Excel
spreadsheet like this:

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

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

' Get the HTML for the control.
DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())

Now, my question is this: In the datagrid, I use colored text and
backgrounds. After exporting, the spreadsheet loses this coloring.

- Am I supposed to be able to maintain colored cells?

- If so, do you know or see anything obvious I need to do?

Thanks,

Dave
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dave,

I think that you do not get a quick answer on your question, I never saw it
but I think you have much more change in the newsgroup

microsoft.public.dotnet.framework.aspnet

I hope you succeed.

Cor

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

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

' Get the HTML for the control.
DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())

Now, my question is this: In the datagrid, I use colored text and
backgrounds. After exporting, the spreadsheet loses this coloring.

- Am I supposed to be able to maintain colored cells?

- If so, do you know or see anything obvious I need to do?

Thanks,

Dave

Nov 20 '05 #2

P: n/a
On Tue, 3 Aug 2004 15:23:18 -0500, "Dave" <da*****************************@stic.net> wrote:

In a VB.NET application, I have a datagrid that I export to an Excel
spreadsheet like this:

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

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

' Get the HTML for the control.
DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())



Now, my question is this: In the datagrid, I use colored text and
backgrounds. After exporting, the spreadsheet loses this coloring.

- Am I supposed to be able to maintain colored cells?

- If so, do you know or see anything obvious I need to do?

The display colors, styles, fonts etc. are not exported from the DataGrid to the Excel Workbook. You
would need to change the formatting via Excel.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #3

P: n/a
Thanks, Paul.

One of the things I didn't mention is that on my datagrid, all but one
column has a default background. In that one column, there is code that
determines which of four colors it should be. When I export the grid to the
workbook, one and only one of those four colors exports correctly each
time.

I would understand if all colors worked okay, or if none of the colors
worked okay, but I don't understand why one of the non-default colors is
handled correctly.

Thanks,

Dave

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:s1********************************@4ax.com...
On Tue, 3 Aug 2004 15:23:18 -0500, "Dave" <da*****************************@stic.net> wrote:
In a VB.NET application, I have a datagrid that I export to an Excel
spreadsheet like this:

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

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

' Get the HTML for the control.
DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())



Now, my question is this: In the datagrid, I use colored text and
backgrounds. After exporting, the spreadsheet loses this coloring.

- Am I supposed to be able to maintain colored cells?

- If so, do you know or see anything obvious I need to do?

The display colors, styles, fonts etc. are not exported from the DataGrid to the Excel Workbook. You would need to change the formatting via Excel.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #4

P: n/a
On Thu, 5 Aug 2004 08:44:35 -0500, "Dave" <da*****************************@stic.net> wrote:

Thanks, Paul.

One of the things I didn't mention is that on my datagrid, all but one
column has a default background. In that one column, there is code that
determines which of four colors it should be. When I export the grid to the
workbook, one and only one of those four colors exports correctly each
time.

I would understand if all colors worked okay, or if none of the colors
worked okay, but I don't understand why one of the non-default colors is
handled correctly.

If you change the color of that particular column does it still export as that color, or, does it
always export as the same color regardless of what color is selected for that column?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5

P: n/a
Dave,

I'm trying to do exactly the same thing you seem to have done with
your code, except that I don't care about the formatting - I just want
grid content. Since you appear to have been successful at that, I'd
like to ask a question of you.

I've copied the code you have listed below into an "Export"
button-click. When I click on the button I get an error message from
Excel saying that it cannot read the file. It appears that Excel is
trying to open the entire aspx page. I would have that it was
supposed to just take the contents of the grid.

Would you care to explain in detail to a newbie how this is supposed
to work? I would truly appreciate it.

Thanks,
Jennifer

"Dave" <da*****************************@stic.net> wrote in message news:<u0*************@tk2msftngp13.phx.gbl>...
In a VB.NET application, I have a datagrid that I export to an Excel
spreadsheet like this:

' Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel"

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

' Get the HTML for the control.
DataGrid1.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())

Now, my question is this: In the datagrid, I use colored text and
backgrounds. After exporting, the spreadsheet loses this coloring.

- Am I supposed to be able to maintain colored cells?

- If so, do you know or see anything obvious I need to do?

Thanks,

Dave

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.