Hi,
I am trying to export my data into excel
I have below code which is perfectly working.
protected void btnExport_Click(object sender, EventArgs e)
{
Handler h1 = new Handler();
DataSet ds = new DataSet();
int RoleId = Convert.ToInt16(Request.Cookies["RoleId"].Value);
if (RoleId == 1)
ds=h1.get_MilestoneReport(1, Convert.ToInt16(Request.Cookies["BB"].Value),"");
else if (RoleId == 3)
ds=h1.get_MilestoneReport(2, Convert.ToInt16(Request.Cookies["BB"].Value),"");
string attachment = "attachment; filename=MileStoneReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
string tab1 = "";
foreach (DataTable table in ds.Tables)
{
foreach (DataColumn column in table.Columns)
{
Response.Write(tab1 + column.ColumnName);
tab1 = "\t";
}
}
tab = "\n";
foreach (DataRow dr in ds.Tables[0].Rows)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
tab = "\n";
}
Response.End();
}
Now the issue is, data which is coming in excel is not coming properly what i mean is
width issue, i want to put proper width for each column and some of the values are coming as
2.07135E+12
if i double click that cell its coming right, here it is 2071351010002.
Somebody please help me in formatting this excel so that it makes sense to people.
Thanks Regards,
SUNIL.