473,804 Members | 4,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview (and Datagrid) exported to Excel

I have an app that gives a user an option to pull an online report into
Excel.

I have the rows formatted in a couple different colors, with a grey
header & footer.

No matter what colors the alternating (and regular) rows are between the
header & footer, they come out an off-white color.

Is there a way to programatically set the colors of cells when they're
exported to excel?

Second question - on the row above the header in the export page, I put
out a confidentiality message. Is there a way to have the background of
that cell a different color other than white? I want to do something to
highlight it or something, to make it stand out somewhat versus the rest
of the report.
Thanks,

BC
May 25 '07 #1
3 3867
KJ
Can you tell us how you are exporting to Excel - are you doing it by setting
the Content-Type header and rendering the control inline, or some other
method?

"Blasting Cap" <go****@christi an.netwrote in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
>I have an app that gives a user an option to pull an online report into
Excel.

I have the rows formatted in a couple different colors, with a grey header
& footer.

No matter what colors the alternating (and regular) rows are between the
header & footer, they come out an off-white color.

Is there a way to programatically set the colors of cells when they're
exported to excel?

Second question - on the row above the header in the export page, I put
out a confidentiality message. Is there a way to have the background of
that cell a different color other than white? I want to do something to
highlight it or something, to make it stand out somewhat versus the rest
of the report.
Thanks,

BC

May 26 '07 #2
KJ - sorry, I forgot to mention that.

I'm doing it by the content-type header & rendering control in-line.

Here's a good bit of the code:
Private Sub RenderGrid()

Dim sFile As String = Session("User") & "-" & Label2.Text
sFile = sFile.Replace("/", "-")

If DataGrid1.Visib le = True Then
ClearControls(D ataGrid1)
End If

If GridView1.Visib le = True Then
ClearControls(G ridView1)
End If
Select Case Session("bc")
Case "Excel"
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Append Header("content-disposition",
"attachment ; filename=" & sFile & ".xls")
Case "Word"
Response.Conten tType = "applicatio n/vnd.ms-word"
Response.Append Header("content-disposition",
"attachment ; filename=" & sFile & ".doc")
End Select

' Remove the charset from the Content-Type header.
Response.Charse t = ""
' Turn off the view state.
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter
Dim hw As New System.Web.UI.H tmlTextWriter(t w)

Label2.RenderCo ntrol(hw)
hw.Write(("<br> "))

Label1.RenderCo ntrol(hw)

' Get the HTML for the control.
If DataGrid1.Visib le = True Then
DataGrid1.Rende rControl(hw)
End If

If GridView1.Visib le = True Then
GridView1.Rende rControl(hw)
End If

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

BC
KJ wrote:
Can you tell us how you are exporting to Excel - are you doing it by setting
the Content-Type header and rendering the control inline, or some other
method?

"Blasting Cap" <go****@christi an.netwrote in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
>I have an app that gives a user an option to pull an online report into
Excel.

I have the rows formatted in a couple different colors, with a grey header
& footer.

No matter what colors the alternating (and regular) rows are between the
header & footer, they come out an off-white color.

Is there a way to programatically set the colors of cells when they're
exported to excel?

Second question - on the row above the header in the export page, I put
out a confidentiality message. Is there a way to have the background of
that cell a different color other than white? I want to do something to
highlight it or something, to make it stand out somewhat versus the rest
of the report.
Thanks,

BC

May 29 '07 #3
KJ
The only thing I can think of is that the CSS styles aren't being
applied correctly - maybe try using inline styles (using the style
attribute) and see if that changes things?
On May 29, 9:15 am, Blasting Cap <goo...@christi an.netwrote:
KJ - sorry, I forgot to mention that.

I'm doing it by the content-type header & rendering control in-line.

Here's a good bit of the code:

Private Sub RenderGrid()

Dim sFile As String = Session("User") & "-" & Label2.Text
sFile = sFile.Replace("/", "-")

If DataGrid1.Visib le = True Then
ClearControls(D ataGrid1)
End If

If GridView1.Visib le = True Then
ClearControls(G ridView1)
End If

Select Case Session("bc")
Case "Excel"
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Append Header("content-disposition",
"attachment ; filename=" & sFile & ".xls")
Case "Word"
Response.Conten tType = "applicatio n/vnd.ms-word"
Response.Append Header("content-disposition",
"attachment ; filename=" & sFile & ".doc")
End Select

' Remove the charset from the Content-Type header.
Response.Charse t = ""
' Turn off the view state.
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter
Dim hw As New System.Web.UI.H tmlTextWriter(t w)

Label2.RenderCo ntrol(hw)
hw.Write(("<br> "))

Label1.RenderCo ntrol(hw)

' Get the HTML for the control.
If DataGrid1.Visib le = True Then
DataGrid1.Rende rControl(hw)
End If

If GridView1.Visib le = True Then
GridView1.Rende rControl(hw)
End If

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

BC

KJ wrote:
Can you tell us how you are exporting to Excel - are you doing it by setting
the Content-Type header and rendering the control inline, or some other
method?
"Blasting Cap" <goo...@christi an.netwrote in message
news:%2******** **********@TK2M SFTNGP04.phx.gb l...
I have an app that gives a user an option to pull an online report into
Excel.
I have the rows formatted in a couple different colors, with a grey header
& footer.
No matter what colors the alternating (and regular) rows are between the
header & footer, they come out an off-white color.
Is there a way to programatically set the colors of cells when they're
exported to excel?
Second question - on the row above the header in the export page, I put
out a confidentiality message. Is there a way to have the background of
that cell a different color other than white? I want to do something to
highlight it or something, to make it stand out somewhat versus the rest
of the report.
Thanks,
BC

May 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4108
by: Seagull Ng | last post by:
Hello all, I am doing my web-based reporting tool in ASP.Net 2.0 using Visual Web Developer 2005. I try to export my populated gridview to Excel spreadsheet but what I got is just a blank spreadsheet with only <div></div> tag in the first cell. Can anyone tell me what actually is the problem? Thanks in advance.
3
1903
by: RTT | last post by:
hey, i made a windows form where i created a datagrid with a datatable as it's datasource. now i want to supplie a save button to my users so the datagrid can be exported to excel. how can i do this? thxs
1
1184
by: Not Me | last post by:
Hi, I use the following code to export a prepared gridview control as an excel spreadsheet. *** Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw)
0
1360
by: Mike P | last post by:
I am using the following code to export my gridview to excel : protected void btnExport_Click(object sender, ImageClickEventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = "";
2
2859
by: Steve Kershaw | last post by:
Hi, I'm working on a project in which I have a Gridview that has data. That Gridview data must be then exported to an Excel spreadsheet. I have successfully displayed the Excel spreadsheet and fill it with data using the Range.InvokeMember(...) method: Range range2 = worksheet.get_Range("A1", "L1"); Object args2 = new Object;
0
1800
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a gridview. I calculated some values in the gridview for the footer of the gridview so basically I am adding all the values that are displayed in the gridview for each column and displaying the total in the footer of the gridview. Now I export the gridview to excel spreadsheet with the code below. Everything is exported well except the footer value become zero in the excel spreadsheet. Can anyone tell me how can i...
1
1142
by: imranabdulaziz | last post by:
Dear all, i am using asp.net ,C# , Microsoft internet explorer 6 version ans iis5.0. My problem is gridview data does not get exported in explorer whereas when i select firefox it exported to excel. i change the internet security setting to low and added the site to trusted sites . what could be the reason. please help.
0
1460
by: mohaaron | last post by:
I am finding that when a GridView is export to Excel by changing the ContentType of the page the Excel file is not readable by OleDb or SQL Server DTS. I also tried using a Excel Reader that I found (http:// www.codeproject.com/csharp/Excel_DataReader.asp) but this also threw an error trying to read the header. I believe that this is all happening because the exported Excel file is in some sort of html table format. Does anyone know...
1
3403
by: Yordan Georgiev | last post by:
I have a search form using master page , which is dynamically generated from the column names of the database - when the users have a search result it should be exported to Excel by clicking the button ... I get the following message : A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.