Reputation: 1897
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?
Upvotes: 1
Views: 18682
Reputation: 21
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";
Upvotes: 2