PC Review


Reply
Thread Tools Rate Thread

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

 
 
Dave
Guest
Posts: n/a
 
      3rd Aug 2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Aug 2004
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
>
>



 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      4th Aug 2004
On Tue, 3 Aug 2004 15:23:18 -0500, "Dave" <(E-Mail Removed)> 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 ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      5th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 3 Aug 2004 15:23:18 -0500, "Dave"

<(E-Mail Removed)> 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 ~~~ (E-Mail Removed)
> Microsoft MVP (Visual Basic)



 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      5th Aug 2004
On Thu, 5 Aug 2004 08:44:35 -0500, "Dave" <(E-Mail Removed)> 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 ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
Jennifer
Guest
Posts: n/a
 
      13th Aug 2004
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" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the functions "LARGE"and "SMALL" in an Excel program Ed Microsoft Excel Programming 2 18th Mar 2008 06:33 PM
How can I use the "Small Caps" Font option in an Excel speadsheet =?Utf-8?B?ZXhlY2Fzc2lzdDE5NzY=?= Microsoft Excel Misc 2 4th Oct 2006 10:40 PM
Question about "Current" and "Detail" Kan D. Microsoft Access Form Coding 1 9th Aug 2006 07:13 PM
Eorror detail msg "Excel caused a divide zero in module excel.exe" =?Utf-8?B?RXJpYw==?= Microsoft Excel Crashes 0 17th Oct 2005 09:01 AM
Datagrid --> Excel Spreadsheet - A "small detail" question Dave Microsoft ASP .NET 0 13th Aug 2004 09:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.