473,404 Members | 2,137 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,404 software developers and data experts.

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

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
5 1805
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Goran Djuranovic | last post by:
Hi all, When I export data from asp.net datagrid to excel spreadsheet, characters such as "é" become "é". It looks like excel doesn't know how to convert these. Anyone? TIA
2
by: | last post by:
I have an app with 2 datagrids that are displayed in a page_load event. I use the following code to render it to an Excel workbook. sFile = sFile.Replace("/", "-") ClearControls(DataGrid1) ...
0
by: Dave | last post by:
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...
2
by: Rob Petersen | last post by:
Can anyone recommend a good, reliable solution or 3rd party component to send a DataGrid or DataTable's contents to Excel? I've tried the following code but it does not work reliably with large...
3
by: Scott M. Lyon | last post by:
I'm trying to figure out a way to export data (actually the result of a Stored Procedure call from SQL Server) into a specified Excel spreadsheet format. Currently, I have the data read into a...
0
by: Leonard | last post by:
I am trying to open an excel spreadsheet that is loaded from a datagrid. I have managed to do this. But, my original .aspx page no longer works. I will try to explain. I have an .aspx page -...
0
by: JLuv | last post by:
What i want to do is take the checked data from a datagrid, send it to a table, then show that table on an Excel Spreadsheet. Here is a little bit of my code... //adminProgress.aspx...
4
by: zacks | last post by:
I have an application that can read an Excel spreadsheet on a computer that doesn't have Excel installed on using the Jet ODBC 4.0 driver. I know need to modify the application to also be able to...
0
by: Maurita | last post by:
Hi All, hope someone can lead me in the right direction. I am in new territory and am unsure what to do after importing an Excel Spreadsheet into my database. 1. The same spreadsheet with new...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.