Gridview (and Datagrid) exported to Excel

B

Blasting Cap

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
 
K

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?
 
B

Blasting Cap

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.Visible = True Then
ClearControls(DataGrid1)
End If

If GridView1.Visible = True Then
ClearControls(GridView1)
End If


Select Case Session("bc")
Case "Excel"
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("content-disposition",
"attachment; filename=" & sFile & ".xls")
Case "Word"
Response.ContentType = "application/vnd.ms-word"
Response.AppendHeader("content-disposition",
"attachment; filename=" & sFile & ".doc")
End Select

' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

Label2.RenderControl(hw)
hw.Write(("<br>"))

Label1.RenderControl(hw)

' Get the HTML for the control.
If DataGrid1.Visible = True Then
DataGrid1.RenderControl(hw)
End If

If GridView1.Visible = True Then
GridView1.RenderControl(hw)
End If

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





BC
 
K

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top