Arabic Problem when Export Data to Excel

Hi Folks,

I faced a problem when you are trying to export arabic data binded in a datagrid or gridview in asp.net 1.x or 2.0 in VS.Net.

The problem is the arabic data is exported as a un-recognized letters “@@@???#######”,since my system is arabic enabled and i can write arabic in my machine.

I checked my code for export to excel,the data is being streamed in a right format but when its appearing in excel it shows as un-recognized letters.

NOTE : YOU HAVE TO CHECK THAT YOUR OFFICE IS SUPPORTING ARABIC BY Open :
START MENU-> OFFICE->OFFICE TOOLS-> LANGUAGE SETTINGS.

The problem exists in office 2003 or even in office 2007.

If you want to see export data to excel in C#,refer to my earlier post :
http://moustafa-arafa.blogspot.com/2007/04/export-more-than-1-grid-in-excel-file.html

The problem wasn’t in to put the character set of the response to UTF-8 or Windows-1256,the problem was when Response.End() is called it throw an exception because the thread has been aborted,simply what you have to do is just replace Response.End()
line by below line :

HttpContext.Current.ApplicationInstance.CompleteRequest();

/* FULL CODE TO EXPORT TO SUPPORT ARABIC *************//////

Response.Clear();
Response.Buffer= true;
Response.ContentType = “application/vnd.ms-excel”;
Response.Charset = “”;//You can set UTF-8 or windows-1256 but this will not solve
this.EnableViewState = false;
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);

MyDGrid.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();

/********************************END OF THE CODE ****************************/


Enjoy .Netting :)



Regards,
Moustafa arafa

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>