title: How to Export Multiple Data Tables to Multiple Worksheets Inside a Single Excel File
body: <p>Below is my C# code for export single table data, but I need to export 3 tables data into one single excel file. I need  to Export Multiple Data Tables to Multiple Worksheets Inside a Single Excel File.</p>
  
  <pre><code> protected void lnkbtn_Submit_Click(object sender, EventArgs e)
    {
      DateTime Fromdate = DateTime.ParseExact(txt_FromDate.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
      DateTime Todate = DateTime.ParseExact(txt_ToDate.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
  
      bo.Dateused = Fromdate;
      bo.Dateused2 = Todate;
  
      DataTable dt = bl.Get_Registrationdetailsbydate(bo);
      gv_Regdetails.DataSource = dt;
      gv_Regdetails.DataBind();
      Session["Fromdate"] = txt_FromDate.Text;
      Session["Todate"] = txt_ToDate.Text;
      if (gv_Regdetails.Rows.Count &gt; 0)
      {
          Session["registrationtable_date"] = dt;
          btnExport.Visible = true;
      }
  
      else
      {
          Session["registrationtable_date"] = null;
          btnExport.Visible = false;
      }
  }
  protected void Button1_Click(object sender, ImageClickEventArgs e)
  {
      DataGrid dg = new DataGrid();
      if (Session["registrationtable_date"] != null)
      {
          dg.DataSource = (DataTable)Session["registrationtable_date"];
          dg.DataBind();
          System.Web.HttpContext.Current.Response.Clear();
          System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=TotalRegistrationDetails.xls");
          System.Web.HttpContext.Current.Response.Charset = "";
          System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
          System.Web.HttpContext.Current.Response.ContentType = "application/vnd.xls";
          System.IO.StringWriter stringwrite = new System.IO.StringWriter();
          System.Web.UI.HtmlTextWriter htmlwrite = new HtmlTextWriter(stringwrite);
          dg.RenderControl(htmlwrite);
          System.Web.HttpContext.Current.Response.Write(stringwrite.ToString());
          System.Web.HttpContext.Current.Response.End();
          Session.Remove("registrationtable_date");
  
          }
        }
      }
  </code></pre>
  
  <p>My stored procedure script:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[Get_Registrationdetailsbydate]
   (
    @Fromdate datetime,
    @Todate datetime
   )
   AS
  BEGIN
  
   select Name,Email,Mobile,SubmissionDate from Registration  WHERE  (CONVERT(varchar(50), SubmissionDate, 101)  BETWEEN @Fromdate AND @Todate) 
  END
  </code></pre>
  
  <p>Thank you in Advance.</p>