title: How to format excel file cells when data exported from SQL Server database
body: <p>I'm exporting some data I have in a database into Excel. Although the below code works fine, I would like to know how to manipulate headers, colours, and generally the way the cells look?</p>
  
  <p>page.aspx</p>
  
  <pre><code>   &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"  SelectCommand="SELECT ID, Number, Title, Name FROM Requests"&gt;
   &lt;SelectParameters&gt;
          &lt;asp:QueryStringParameter DefaultValue="" Name="ID" 
              QueryStringField="ID" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  
    &lt;asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
      AutoGenerateRows="False" DataKeyNames="RequestID" DataSourceID="SqlDataSource1"&gt;
      &lt;Fields&gt;
             &lt;asp:BoundField DataField="ID" HeaderText="ID" 
              SortExpression="ID" InsertVisible="False" ReadOnly="True" /&gt;
          &lt;asp:BoundField DataField="Number" HeaderText="Number" 
              SortExpression="Number" /&gt;
          &lt;asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /&gt;
          &lt;asp:BoundField DataField="Name" HeaderText="Name" 
              SortExpression="Name" /&gt;
  </code></pre>
  
  <p>
      </p>
  
  <p>page.aspx.vb  </p>
  
  <pre><code>    Dim tw As New System.IO.StringWriter()
      Dim hw As New System.Web.UI.HtmlTextWriter(tw)
  
      Dim dgGrid As New DetailsView()
  
      dgGrid.DataSource = SqlDataSource1
  
      hw.WriteLine("&lt;b&gt;Title here&lt;/b&gt;")
  
      dgGrid.HeaderStyle.Font.Bold = True
      dgGrid.DataBind()
      dgGrid.RenderControl(hw)
  
      Response.AddHeader("content-disposition", "attachment;filename=ReportOuput.xls")
      Response.ContentType = "application/vnd.ms-excel"
      Me.EnableViewState = False
      Response.Write(tw.ToString())
      Response.End()
  </code></pre>