title: export gridview to excel with custom value formatting
body: <p>i have in my content page 4 things:</p>
  
  <ul>
  <li>a single gridview</li>
  <li>query buttons that execute database views and display the results of the queries inside the view in the gridview</li>
  <li>export to excel button that exports the gridview into excel</li>
  <li>send email with the excel above as an attachment</li>
  </ul>
  
  <p>they work fine, however i noticed a strange problem with the formatting of some of the cells within a column, the column has 2 formats applied to the values, "number" and "general", being "number" the incorrect one.</p>
  
  <p>here are some pics of the first few results to illustrate what i'm saying:</p>
  
  <p>in sql server</p>
  
  <p><img src="https://i.stack.imgur.com/UDK9R.png" alt="sql"></p>
  
  <p>in the content page</p>
  
  <p><img src="https://i.stack.imgur.com/Q2W5m.png" alt="content page"></p>
  
  <p>in excel</p>
  
  <p><img src="https://i.stack.imgur.com/1Xw44.png" alt="excel"></p>
  
  <p>notice that in sql server and on the page, the cells are displayed with the correct formatting, which is XXXXX.etc (<strong>general formatting</strong>) but the cells with more numbers get formatted as "number"</p>
  
  <p>i'll post some code bellow:</p>
  
  <p>gridview</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"&gt;&lt;/asp:GridView&gt;
  </code></pre>
  
  <p>export to excel button</p>
  
  <pre><code>protected void Buttonexcel_Click(object sender, EventArgs e)
  {
  
      try
      {
          Response.Clear();
          Response.Buffer = true;
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.Charset = "";
          Response.AddHeader("content-disposition", "attachment;filename=dados.xls");
          StringWriter sWriter = new StringWriter();
          HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
          GridView1.RenderControl(hWriter);
          Response.Output.Write(sWriter.ToString());
          Response.Flush();
          Response.End();
      }
      catch (Exception ex)
      {
          Label1.Text = ex.ToString();
      }
  
  }
  </code></pre>
  
  <p><strong>is there a way that i can force only "general" formatting for the entire xls?</strong></p>