Dodgy Characters Exporting to Excel

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

  1. 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()

    <-----
    , Sep 26, 2005
    #1
    1. Advertising

  2. 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
    , Sep 26, 2005
    #2
    1. Advertising

  3. Guest

    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goran Djuranovic
    Replies:
    0
    Views:
    349
    Goran Djuranovic
    Dec 10, 2004
  2. Adam Knight

    Dodgy Nested Grid Update!

    Adam Knight, Aug 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    382
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Aug 9, 2005
  3. ChrisN
    Replies:
    0
    Views:
    832
    ChrisN
    Sep 19, 2006
  4. Elisabeth Svensson via .NET 247

    Handling special characters when exporting DataGrid to Excel

    Elisabeth Svensson via .NET 247, Aug 4, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    561
    Pete Fearn
    Dec 21, 2004
  5. Exporting to Excel with Chinese Characters

    , Oct 15, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    280
Loading...

Share This Page