Link to home
Start Free TrialLog in
Avatar of Fraser_Admin
Fraser_AdminFlag for Canada

asked on

Export GridView to Excel

See code below.  I have the following code to write my contents of my gridview to excel.  In one column I am sometimes getting a funny character and I'm not sure why or how to get rid of it.  I could intercept it in the rowdatabound event?  How would I find and replace this character.  Any ideas on what would cause this?

MYTESTDATA  Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 

'Write out what is in the Gridview
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        GridView1.Caption = "Grade Groups"
        Response.AddHeader("Content-Disposition", "attachment; filename=" + GridView1.Caption + ".xls")
        Response.Charset = ""
        Me.EnableViewState = False
        Dim oStringWriter As New System.IO.StringWriter
        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
        GridView1.Caption = ""
        GridView1.FooterRow.Visible = False
        GridView1.RenderControl(oHtmlTextWriter)

        Response.Write(oStringWriter.ToString())
        Response.[End]()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial