C# .NET - how to export data from multiple datatable to multiple excel worksheet by modifying below

Asked By mani on 24-Jan-13 06:24 AM
hi...i using below code for export data to excel from dataset..it contians single datatable..but i need to change these code to get data from more than one datatable to more that one excel worksheet..please any one help me with same code..because codes  refer is working as saving in specified path..but i want  to excel as downloading..
help will be appreciated..

namespace ExcelUtility
{

    public class DataSetToExcel
    {
      public DataSetToExcel()
      {
        //
        // TODO: Add constructor logic here
        //
      }
      public static void Convert(DataSet ds, HttpResponse Response)
      {
        Response.Clear();
        Response.Charset = string.Empty;
        HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "stock_varience.xls"));
        Response.ContentType = "application/vnd.ms-excel";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
        System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
        dg.DataSource = ds.Tables[0];
        dg.DataBind();
        dg.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
        
      }
    }
}
Sum Green replied to mani on 27-Jan-13 10:41 PM
Hello, Please try to use this .NET Data Export component: Spire.DataExport for .NET. It enables to export data from datatable to more than 3 excel worksheets.

You can get its example here:http://exportdata.codeplex.com/
White Ashlin replied to Sum Green on 29-Jan-13 02:41 AM
I think this article may help you:  http://www.c-sharpcorner.com/UploadFile/83fe73/solutions-to-export-data-from-database-to-excel-in-C-Sharp/