Charset problem (dataset to excel)

M

Morten Snedker

The code below is used to get the content of a dataset to Excel and it
works quite okay, except:

Special Danish charachters look crappy when shown in Excel. Any ideas
if the problem can be solved?

response.Clear()
response.Charset = "iso-8859-2"
response.ContentType = "application/vnd.ms-excel"

Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New DataGrid
dg.DataSource = ds.Tables(0)
dg.DataBind()
dg.RenderControl(htmlWrite)

response.Write(stringWrite.ToString)
response.End()


Regards /Snedker
 
J

Joerg Jooss

Thus wrote Morten Snedker morten_spammenot_ATdbconsult.dk,
The code below is used to get the content of a dataset to Excel and it
works quite okay, except:

Special Danish charachters look crappy when shown in Excel. Any ideas
if the problem can be solved?

response.Clear()
response.Charset = "iso-8859-2"

Don't use HttpResponse.Charset -- that has no effect on the actual encoding
being used (it just sets an attribute of the Content-Type header). Instead,
use

Response.ContentEncoding = Encoding.GetEncoding("iso-8859-2");

which also sets HttpResponse.Charset implicitly.

Cheers,
 
M

Morten Snedker

On Thu, 25 Jan 2007 21:08:12 +0000 (UTC), Joerg Jooss

Can I call you honey? :)

Just changed to iso-8859-1 and all is well. Thanks a bunch for the
iceing on the cake!

/Regards
 

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top