title: How do you generate an Excel 2007 file in ASP.NET without getting a warning message?
body: <p>Whenever I open an xls file I generated on my ASP.NET page with Excel 2007, I get the following error:</p>
  
  <blockquote>
    <p>The file you are trying to open, 'filename.xls', is in a different
    format than specified by the file extension. Verify that the file is
    not corrupted and is from a trusted source before opening the file. Do
    you want to open the file now?</p>
  </blockquote>
  
  <p>If I click 'Yes', everything looks fine, but it's annoying to our customers to have to click through it each time.  If they use 2003, no problem, but on 2007 it gives this error.  Here's the code I use:</p>
  
  <pre><code>string style = @"&lt;style&gt; .text { mso-number-format: \@ } &lt;/style&gt; ";
  
  Response.Clear();
  Response.AddHeader("content-disposition", string.Format("attachment;filename=OperationsReport_Rejects_{0}.xls", DateTime.Today.ToString("yyyyMMdd")));
  Response.Charset = "";
  Response.ContentType = "application/vnd.xls";
  
  StringWriter stringWrite = new StringWriter();
  HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  
  reportOperationsRejectsGridView.RenderControl(htmlWrite);
  Response.Write(style);
  Response.Write(stringWrite.ToString());
  Response.End();
  </code></pre>
  
  <p>Does anyone know what is causing it to behave differently on 2003 and 2007?</p>