Exporting data from a repeater to an Excel sheet

csharp Mexico
  • 13 years ago

    I’m using this code to export data from a repeater to an Excel sheet:


    Response.Clear();
    Response.Buffer= true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment;filename=Clientes.xls");
    Response.Charset = "";
    this.EnableViewState = false;
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    Repeater1.RenderControl(oHtmlTextWriter);
    Response.Write(oStringWriter.ToString());
    Response.End();


    Excel sheet when is displayed contains data from repeater, notwithstanding accents and Spanish letter ñ containing within data are not drawing correctly, e.g.:


    México        it is drawing as        México
    López        it is drawing as        López
    Villafaña        it is drawing as        Villafaña
    María        it is drawing as        MarÃa


    ¿Does somebody knows what is the reason about it and how can I fix it?



    I’ll appreciate your help.


    A.L.

  • 13 years ago

    Nobody have had an experience such this one?

  • 13 years ago

    My first guest would be to check your character encoding, you'll probably have to set it to UTF-8...

  • 13 years ago
  • 13 years ago

    I already tried with utf-8, iso-latin-1, unicode, iso-8859-1, and problem still is therein.
    I will study your link.
    Thanks yo Rasta.
    A.L.

  • 13 years ago

    I'm curious, try-out utf-7, solved a problem once for me, even though it ain't logical to use it.

  • 13 years ago

    Neither with utf-7

  • 13 years ago

    Doh

  • 13 years ago

    My Canadian friend:


    Thanks you very much for your interest in my trouble.


    At last I found the way to achieve it:


    Below this line:


    Response.ContentType = "application/vnd.ms-excel";


    I insert this line :


    Response.ContentEncoding = System.Text.Encoding.UTF7;


    I hope this be useful people having a similar trouble.


    A.L.



  • 13 years ago

    That was exactly what I meant by saying:"try to set the encoding to UTF8 or UTF7". But at least it works...
    Thats really strange though, anyway...


    have fun.

  • 13 years ago

    When I tested your code, how do you:


    remove all the HTML tags?
    Have each data be placed in a seperate cell?


    Thanks

  • 12 years ago

    Hi all, I have same problem.  In xls file don't show Turkish characters "sgüç". In my code:


    ....
    Response.Charset = "windows-1254";//for turkish charset
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");//i use UTF-7 UTF-16 and UTF-32 but they don't work.
    How can i solve this problem? Please help...

  • 12 years ago

    Quote:
    [1]Posted by dev.net on 23 Jan 2006 09:44 PM[/1]
    Hi all, I have same problem.  In xls file don't show Turkish characters "sgüç". In my code:


    ....
    Response.Charset = "windows-1254";//for turkish charset
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");//i use UTF-7 UTF-16 and UTF-32 but they don't work.
    How can i solve this problem? Please help...



    hi have you sold this problem mate? indeed i have purely same problem like you

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra