title: Export HTML Table to Excel and Format The Excel file
body: <p>I have the following code:<br></p>
  
  <pre><code>&lt;tfoot&gt;
  &lt;tr&gt;
    &lt;td&gt;Tot&lt;/td&gt;
    &lt;td&gt;60&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;30&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td&gt;Avg&lt;/td&gt;
     &lt;td&gt;20&lt;/td&gt;
     &lt;td&gt;&lt;/td&gt;
     &lt;td&gt;10&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p></p>
  
  <p>Code Behind:</p>
  
  <pre><code>public string getWhileLoopData() 
  {
   string htmlStr = "";
   SqlConnection thisConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
   SqlCommand thisCommand = thisConnection.CreateCommand();
   thisCommand.CommandText = "SELECT * FROM MyTable WHERE TheDate = @TheDate";
   thisCommand.Parameters.AddWithValue("@TheDate", txtDate.Text);
  
  
  int totnum1 = 0;
  decimal totnum2 = 0;
  int numRow = 0;
  decimal avg1 = 0;
  decimal avg2 = 0;
  
  
  
   thisConnection.Open();
   SqlDataReader reader = thisCommand.ExecuteReader();
  
   while (reader.Read()) {
       int id = reader.GetInt32(0);
  
       int Number01 = reader.GetInt32(1);
       DateTime TheDate = reader.GetDateTime(2);
       Decimal Number02 = reader.GetDecimal(3);
  
       totnum1 += reader.GetInt32(1);
       totnum2 += reader.GetInt32(3);
       numRow ++;
  
       //string Pass = reader.GetString(2);
       htmlStr += "&lt;tr&gt;&lt;td&gt;" + id + "&lt;/td&gt;&lt;td&gt;" + Number01 + "&lt;/td&gt;&lt;td&gt;" + TheDate + "&lt;/td&gt;&lt;td&gt;" + Number02 + "&lt;/td&gt;&lt;/tr&gt;";
   }
  
   thisConnection.Close();
  
  avg1 = totnum1 / numRow;
  avg2 = totnum2 / numRow;
  
  htmlStr += string.Format("&lt;tfoot&gt;&lt;tr&gt;&lt;td&gt;Tot&lt;/td&gt;&lt;td&gt;{0}&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;{1}&lt;/td&gt;&lt;/tr&gt;", totnum1 , totnum2 );
  htmlStr += string.Format("&lt;tfoot&gt;&lt;tr&gt;&lt;td&gt;Avg&lt;/td&gt;&lt;td&gt;{0}&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;{1}&lt;/td&gt;&lt;/tr&gt;&lt;/tfoot&gt;", avg1 , avg2 );
  
  
   return htmlStr;
  }
  </code></pre>
  
  <p>Does anyone know how to export it to an Excel file? But I want the excel file formatted. i.e.: Put an image on the Excel file after it is exported, font size, color, fill color, etc. All formatting needs to be done from code behind.</p>