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

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

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
 
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
 
¤ 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 ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
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





 
¤ 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 ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
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
 
Back
Top