Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid export to excel - color extends over gridlines

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
hello-

I have a datagrid that I export to excel which I have dynamically colored on export- when I export it into excel, the colors are there (the green is gray for some reason??) but the color just keeps extending out over the boundaries of the grid lines- can I have the colors just stay in the grid itself??

Thanks!
 
Depends. How are you exporting it to Excel?

-I hate Microsoft!
-Forever and always forward.
 
I'm doing it via a button in the web form:

Code:
Private Sub btnExportBP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportBP.Click
        RenderGridToExcelFormat(DGViewRequests, txtFilename.Text)

    End Sub
    Sub RenderGridToExcelFormat(ByVal grid As DataGrid, ByVal saveAsFile As String)
        If grid.Items.Count.ToString + 1 < 65536 Then
            HttpContext.Current.Response.Clear()
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & saveAsFile & ".xls")
            HttpContext.Current.Response.Charset = ""
            Dim frm As HtmlForm = New HtmlForm
            grid.EnableViewState = False
            Controls.Add(frm)
            Dim tw As New System.IO.StringWriter
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            frm.Controls.Add(DGViewRequests)
            frm.RenderControl(hw)
            HttpContext.Current.Response.Write(tw.ToString())
            HttpContext.Current.Response.End()
        Else
            HttpContext.Current.Response.Write("Too many rows - Export to Excel not possible")
        End If
    End Sub
 
Yea, don't post the same question in more than one forum. This is an ASP.NET question, not a VB.NET question.
 
I posted it here first and the realized it was ASP.NET - sorry -that's why it's in 2 places. Can't delete it otherwise I would have, unless you know of a way to do that?
 
I think you have to red flag the post.. use the link in the post.. and then you can specify why it should be deleted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top