I am able to export data table to excel sheet. But, String values are appearing as numericals in excel sheet.
For Eg: 616031100038 is a string in my datatable but in excel sheet it is appearing as a numerical i.e., 6.16031E+11.
I am using following code. dtSO is the datatable with valid content.
string attachment = "attachment; filename=exportdata.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dtSO.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dtSO.Rows)
{
tab = "";
for (i = 0; i < dtSO.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
Is there any way I can format these cells in Response object?