title: Export .NET DataTable to Microsoft Excel and Format Results
body: <p>I want to set the row height with eporting my data to Excel.  I tried the below, but am getting a debug error of </p>
  
  <blockquote>
    <p>Unable To Cast object type of 'System.Web.UI.WebControls.DataGridItem' to type
    'System.Web.UI.WebControls.GridViewRow'</p>
  </blockquote>
  
  <p>And this is my syntax</p>
  
  <pre><code>public void ExportToExcel(DataTable dataTable)
  {
    string filename = "Bamo.xls";
    StringWriter tw = new System.IO.StringWriter();
    HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
    DataGrid dgGrid = new DataGrid();
    dgGrid.DataSource = dataTable;
    dgGrid.DataBind();
    int j = 0;
    foreach(GridViewRow gvrow in dgGrid.Items)
    {
      if (j % 2 != 0)
      {
          for (int k = 0; k &lt; gvrow.Cells.Count; k++)
          {
              gvrow.Cells[k].Style.Add("Height", "10");
          }
      }
      j++;
    }
  }
  </code></pre>