Solved

export grid view to excel encoding problem

Posted on 2011-09-18
4
3,213 Views
Last Modified: 2012-05-12
i am exporting grid view into excel
but i am having problem in encoding
arabic characters are not displayed properly  
 
public void ExportGridViewToExcel(HttpResponse Response, GridView GridView_Excel)
    {
        string attachment = "attachment; filename=Transactions.xls";

        Response.ClearContent();

        HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
        HttpContext.Current.Response.Charset = "utf-8";

        Response.AddHeader("content-disposition", attachment);

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

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        GridView_Excel.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();

    }

Open in new window


any help ??? !!!!!!
public void ExportGridViewToExcel(HttpResponse Response, GridView GridView_Excel)
    {
        string attachment = "attachment; filename=Transactions.xls";

        Response.ClearContent();

        HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
        HttpContext.Current.Response.Charset = "utf-8";

        Response.AddHeader("content-disposition", attachment);

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

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        GridView_Excel.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();

    }

Open in new window

0
Comment
Question by:AhmedHindy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36558064
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 36559128

Add Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />") in your code.

Refer: http://forums.asp.net/t/1467766.aspx

0
 
LVL 4

Author Closing Comment

by:AhmedHindy
ID: 36954698
it worked
0
 
LVL 4

Author Comment

by:AhmedHindy
ID: 37023762
add this and it worked
:)

Response.Charset = "";
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question