CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Question Issues saving HTML with Content-Disposition

    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.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Issues saving HTML with Content-Disposition

    It may be a font issue, IMHO. What Font are you using inside your text that you are sending? Excel may not have that font, or you'd have to set Excel's font.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured