Dodgy Characters Exporting to Excel

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

<-----
 
P

postings

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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top