locked
Export GridView To Excel " Error Special Characters in Header " RRS feed

  • Question

  • User-1775491976 posted

    Hi All

    I'm using this Code for Exporting Gridview to Excel file

    and it works fine for Alllllllll Pages and Grids

    But only one have problem I don't know why !!!  ( The Problem is Special Character in header Like ÙƒÙˆØ¯ الصنف )

    Please Help 

    and remember again ( it works correctly for all gridviews in my project but only one has this problem )

            Response.Clear();
            Response.Buffer = true;
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Charset = "";
            string FileName = "Search Kill Prods " + DateTime.Now.ToString("dd/MM/yyyy") + ".xls";
            StringWriter strwritter = new StringWriter();
            HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
            GridKill.GridLines = GridLines.Both;
            GridKill.AllowPaging = false;
            GridKill.ShowHeader = true;
    
            GridKill.HeaderRow.ForeColor = System.Drawing.Color.White;
            GridKill.HeaderStyle.Font.Bold = true;
            GridKill.RenderControl(htmltextwrtter);
            Response.Write(strwritter.ToString());
            
            Response.End();
    Monday, October 10, 2016 8:07 AM

Answers

  • User1724605321 posted

    Hi Eng.Ranya,

    Try to add below lines :

    Response.ContentEncoding = System.Text.Encoding.Unicode;
    Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
    

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 11, 2016 3:24 AM