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
Hi!

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!
 
how exactly are you converting into excel? is it a HTML file saved as XLS???

Known is handfull, Unknown is worldfull
 
Using VB.net via a button...

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
 
hi,

since the output is in HTML format i would suggest that you rename the file to .html and open it in IE.

Check how it looks there...

Known is handfull, Unknown is worldfull
 
It does open up correct in HTML- so how do I fix this to open correctly in Excel? I added the frm info to get around the error about not having run at server in the form tag, even though it was there....UGH!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top