Dodgy Characters Exporting to Excel

Discussion in 'ASP .Net' started by postings, Sep 26, 2005.

  1. postings

    postings Guest

    Hi

    Could you possibly look at the code below that exports a datagrid to
    Excel in ASP.NET?
    It works fine, but characters such as quotes come out garbled.
    i.e. "Fred's House" will come out in the spreadsheet as "Fred’s
    House".
    Could you give me any pointers here? Is it the character set or
    something.

    Many thanks

    Alex

    ----->

    'Note DGContacts is a datagrid
    Response.ContentType = "application/vnd.ms-excel"
    ' Remove the charset from the Content-Type header.
    Response.Charset = ""
    ' Turn off the view state.
    Me.EnableViewState = False
    DGContacts.AllowSorting = False
    DGContacts.AllowPaging = False
    DGContacts.Columns.Remove(DGContacts.Columns(0))
    Call populatedatagrid()

    Dim tw As New System.IO.StringWriter
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)

    ' Get the HTML for the control.
    DGContacts.RenderControl(hw)
    ' Write the HTML back to the browser.

    Dim strFileName As String = "products.xls"

    Response.Clear()
    Response.Buffer = True
    Response.Expires = 0
    ' Change the HTTP header to reflect that an image is being passed.
    Response.AddHeader("Content-Disposition", "attachment; filename=" &
    strFileName)
    Response.Flush()
    Response.Write(tw.ToString())
    Response.End()

    <-----
     
    postings, Sep 26, 2005
    #1
    1. Advertisements

  2. postings

    postings Guest

    In reference to last post and just in case it is not being displayed
    properly in your client...
    "Fred's House" will come out in the spreadsheet as "Fred/â/€/™/s
    House". (please remove the back slashes).

    Cheers!

    Alex
     
    postings, Sep 26, 2005
    #2
    1. Advertisements

  3. postings

    postings Guest

    postings, Sep 26, 2005
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.