Dodgy Characters Exporting to Excel

  • Thread starter Thread starter postings
  • Start date Start date
P

postings

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

<-----
 
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
 
Back
Top