Exporting HTML report to Excel

Sep 2 2008 8:32 AM

I have created a HTML report dynamically. I use the following code to export it to Excel.

Response.ContentType = "application/vnd.ms-excel";

Response.AppendHeader("content-disposition", "attachment; filename= Center_Wise_Registration_Statistics_" + DateTime.Now.ToLongDateString());

Response.Charset = "";

System.IO.StringWriter sw = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);

hw.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Html);

LabelReportBody.RenderControl(hw);

hw.RenderEndTag();

Response.Write(sw);

Response.End();

 

The problem is, the saved excel file is in a HTML format and when opened, a message box appear stating this fact.

How can i save this report in pure Excel format? Can any one help?


Answers (2)