i want to create a function that would export an excell file according to a dynamically created table in web page..as in same format..please help me
please see my snippet:
GridView1.AllowPaging = true;
StringWriter tw = new StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
HtmlForm frm = new HtmlForm();
string strTmpTime = (System.DateTime.Today).ToString();
string strTmpTime = (System.DateTime.Today).ToString();
if (strTmpTime.IndexOf("/") != -1)
{
strTmpTime = strTmpTime.Replace("/", "-").ToString().Trim();
}
if (strTmpTime.IndexOf(":") != -1)
{
strTmpTime = strTmpTime.Replace(":", "-").ToString().Trim();
}
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=sheet.xls");
Response.Charset = "UTF-8";
EnableViewState = false;
Controls.Add(frm);
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
{
strTmpTime = strTmpTime.Replace("/", "-").ToString().Trim();
}
if (strTmpTime.IndexOf(":") != -1)
{
strTmpTime = strTmpTime.Replace(":", "-").ToString().Trim();
}
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=sheet.xls");
Response.Charset = "UTF-8";
EnableViewState = false;
Controls.Add(frm);
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
this code gives an error upon opening the excel file:

Bhabani PrasadPosted Jun 10, 2014, 3:11 AM
Bhabani PrasadPosted Jun 10, 2014, 3:10 AM
mary jean ligasPosted Jun 10, 2014, 1:32 AM
Abhay ShankerPosted Jun 10, 2014, 1:24 AM
For More details check below url
http://support.microsoft.com/kb/948615