title: Export data excel in asp .net mvc using OpenXml
body: <p>I have a requirement for export data to excel using open Xml plug in. And I want to style excel head boarder colour. I tried different method to achieve my requirement. I would like to export my data table to excel.</p>
  
  <blockquote>
    <p>My Code as follows</p>
  </blockquote>
  
  <pre><code> public ActionResult ExportToExcel()
          {
              var products = new System.Data.DataTable("teste");
              products.Columns.Add("Name", typeof(string));
              products.Columns.Add("Age", typeof(int));
              products.Columns.Add("Gender", typeof(string));
              products.Columns.Add("Salary", typeof(int));
              products.Rows.Add("Basil", 34, "male", 40000);
              products.Rows.Add("Varghese", 34, "male", 40000);
              products.Rows.Add("George", 34, "male", 40000);
              products.Rows.Add("John", 34, "male", 40000);
  
  
              var grid = new GridView();
              grid.DataSource = products;
              grid.DataBind();
  
              Response.ClearContent();
              Response.Buffer = true;
              Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
              Response.ContentType = "application/ms-excel";
  
              Response.Charset = "";
              StringWriter sw = new StringWriter();
              HtmlTextWriter htw = new HtmlTextWriter(sw);
  
              grid.RenderControl(htw);
  
              Response.Output.Write(sw.ToString());
              Response.Flush();
              Response.End();
  
              return View("MyView");
          }
  </code></pre>