Hi I have code that generates an excel report from data in a gridview however when the gridview is empty and you download the report it opens in excel with a <div> tag. Any ideas how I can get the html tags to disappear and possibly just display the column headings with no data beneath them?
My code for generating the excel report is
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string filename = "report.xls";
StringWriter strWriter = new StringWriter();
HtmlTextWriter htmlTxt = new HtmlTextWriter(strWriter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
GridView1.GridLines = GridLines.Both;
GridView1.HeaderStyle.Font.Bold = true;
GridView1.RenderControl(htmlTxt);
Response.Write(strWriter.ToString());
Response.End();
Thanks