Home > Interview Questions > .Net Framework > problèm with arabic exporting datatable to excel

problèm with arabic exporting datatable to excel

by kh   on 17/06/2014   Category: .Net Framework   |  Level: Beginner   |  Views: 1098    |  Points: 25     |  Starter 


I have problèm with arabic when i exporting data from datatable to excel
my method
protected void UploadDataTableToExcel(DataTable dtRecords)
{

string XlsPath = Server.MapPath(@"~/Add_data/test.xls");
string attachment = string.Empty;
if (XlsPath.IndexOf("\\") != -1)
{
string[] strFileName = XlsPath.Split(new char[] { '\\' });
attachment = "attachment; filename=" + strFileName[strFileName.Length - 1];
}
else
attachment = "attachment; filename=" + XlsPath;
try
{
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Clear();
// Response.Write("<meta http-equiv=\"application/vnd.ms-excel\" content=\"text/html; charset=utf-8\" />");
string tab = string.Empty;

foreach (DataColumn datacol in dtRecords.Columns)
{
Response.Write(tab + datacol.ColumnName);
tab = "\t";
}
Response.Write("\n");

foreach (DataRow dr in dtRecords.Rows)
{
tab = "";
for (int j = 0; j < dtRecords.Columns.Count; j++)
{
Response.Write(tab + Convert.ToString(dr[j]));
tab = "\t";
}

Response.Write("\n");
}

Response.End();
}
catch (Exception ex)
{
//Response.Write(ex.Message);
}
}


« How can you verify that the page is Post back or not?
» what is use of DataKeynames attribute in gridview?
Post Question  |  Question Home

Recent Posts

User Responses


No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts