1

I have read this article that exports datatable to excel file. It worked great.

Export DataTable to Excel File

and the code is below:

dt = city.GetAllCity();//your datatable 
string attachment = "attachment; filename=city.xls"; 
Response.ClearContent(); 
Response.AddHeader("content-disposition", attachment); 
Response.ContentType = "application/vnd.ms-excel"; 
string tab = ""; 
foreach (DataColumn dc in dt.Columns) 
{ 
    Response.Write(tab + dc.ColumnName); 
    tab = "\t"; 
} 
Response.Write("\n"); 
int i; 
foreach (DataRow dr in dt.Rows) 
{ 
    tab = ""; 
    for (i = 0; i < dt.Columns.Count; i++) 
    { 
        Response.Write(tab + dr[i].ToString()); 
        tab = "\t"; 
    } 
    Response.Write("\n"); 
} 
Response.End(); 

But when I use this codes, the korean characters are all broken. Can anyone help me with this problem?

4
  • It may be down to Excel not recognising the unicode need to display the characters. You probably need a header to indicate that. Commented Oct 21, 2011 at 0:45
  • which header shall I indicate? Commented Oct 22, 2011 at 4:01
  • ContentType charset en.wikipedia.org/wiki/List_of_HTTP_header_fields#Responses make sure you include UTF8 as shown in the article Commented Oct 23, 2011 at 1:40
  • Of course I put utf-8 in head. Anything else?? Commented Oct 23, 2011 at 6:08

1 Answer 1

2

I use windows-1254 character set for Turkish. I guess KS_X_1001 will work for you. For more sets : http://en.wikipedia.org/wiki/Character_encoding

Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
Response.Charset = "windows-1254";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.