title: Save html table to Excel
body: <p>I see this question has been asked quite a few times before but just in case it may have escaped some eyes I state the problem again</p>
  
  <p>Our ASP.Net web app displays some reports rendered as onscreen html tables and we also have export functionality. It's a standard code</p>
  
  <pre><code>Table a = new Table();
  
  Response.ClearContent();
  Response.Buffer = true;
  Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
  Response.ContentType = "application/ms-excel";
  StringWriter sw = new StringWriter();
  HtmlTextWriter htw = new HtmlTextWriter(sw);
  gridName.RenderControl(htw);
  Response.Write(sw.ToString());
  Response.End();
  </code></pre>
  
  <p>So far so good. The problem is, when exporting to excel it actually gets saved as html, so when the file is opened by Excel, it comes up with the warning saying the format is not correct. It was not much of a problem as after the warning the file will open. </p>
  
  <p>But with IE11 sometimes these files refuse to open saying format is not correct. As IE11 will be rolled out to more and more user, we will have to fix this problem. The options I have are</p>
  
  <ol>
  <li>Find a way to save it as XLS file and not HTML</li>
  <li>Rewrite the entire output as excel when click on export instead of rendering the output of the control to excel. We do use Aspose in our project, so I can go that way</li>
  </ol>
  
  <p>I did try to find out, but couldn't find any thing that lets you save the content as actual xls data and not html. I am sure this is a very generic problem, so if anyone have any solution or suggestion on the same.</p>
  
  <p>If nothing works I will have to go with option 2 which is more work considering the formatting and styling.</p>