Hi guys, I have some issues, saving a HTML content into Excel format. I just populate a StringBuilder and then display it into a WebControl Panel, juzt like this:
Code:
resultados.Controls.Add(new LiteralControl(sb.ToString()));
And then I set the ContentType and I add a header to download the content. This is the code:


Code:
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Indicador.xls");
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "";
Response.Write(sb.ToString());
The data that I get from the database, which I display into the StringBuilder. Sometimes the whole document get disturbed with strange characteres, like if it wasn´t UTF-8 text.

It's very strange and it happened to me a lot of times and I want to know once and for all what is happening.

This is one example of the text that causes the whole mess.


"La tasa está calculada a mitad del per*odo. La etiqueta 1987 representa el per*odo 1987-1992. La etiqueta 1992 representa el per*odo 1992-1997. La etiqueta 1997 representa el per*odo 1997-2002. La etiqueta 2004 representa el per*odo 2004-2009."

As you can see, it's spanish and it may be because the accents.

If I only take till the second sentences, it doesn't happend, and you can realize that "está" and "per*odo" have accent. Therefore it's not because the accent.

Afterwards, I take till the third sentence and everything get into a mess... and I can't find what is happening. There must be some special characteres, that I cannot see? Also de fourth sentence make some noise on the document.

¿What is going on with the encoding process?

I will really appreciate if you could advise me some how.

Thank you in advance.

Raul Bolaños.