Can export more than on table in a dataset to Excel

Discussion in 'ASP .Net' started by =?Utf-8?B?YWQ=?=, Oct 6, 2004.

  1. I used the code below to export a table in a dataset to Excel.
    It can export only on table at a time.
    Can export more than on table in a dataset to Excel


    public static void Convert(System.Data.DataSet ds, int TableIndex,
    System.Web.HttpResponse response)
    {
    if (TableIndex > ds.Tables.Count - 1)
    {
    Convert(ds, response, ds.Tables[0].TableName);
    }
    response.Clear();
    response.Charset = "";
    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[TableIndex];
    dg.DataBind();
    dg.RenderControl(htmlWrite);
    response.Write(stringWrite.ToString());
    response.End();
    }
    =?Utf-8?B?YWQ=?=, Oct 6, 2004
    #1
    1. Advertising

  2. There are a variety of ways you can export content to Excel from ASP.NET.
    This article covers most of them:
    http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "ad" <> wrote in message
    news:...
    >I used the code below to export a table in a dataset to Excel.
    > It can export only on table at a time.
    > Can export more than on table in a dataset to Excel
    >
    >
    > public static void Convert(System.Data.DataSet ds, int TableIndex,
    > System.Web.HttpResponse response)
    > {
    > if (TableIndex > ds.Tables.Count - 1)
    > {
    > Convert(ds, response, ds.Tables[0].TableName);
    > }
    > response.Clear();
    > response.Charset = "";
    > 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[TableIndex];
    > dg.DataBind();
    > dg.RenderControl(htmlWrite);
    > response.Write(stringWrite.ToString());
    > response.End();
    > }
    Steve C. Orr [MVP, MCSD], Oct 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia

    How to export a dataset to excel?

    Luis Esteban Valencia, Nov 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,971
    =?Utf-8?B?dmluYXk=?=
    Nov 3, 2004
  2. Sachin Salgarkar

    Export DataSet/ XML as Excel Sheet

    Sachin Salgarkar, Aug 4, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    7,549
    ritzkandy
    Sep 11, 2008
  3. =?Utf-8?B?TGFtaXM=?=

    export dataset to excel

    =?Utf-8?B?TGFtaXM=?=, Aug 29, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    501
    =?Utf-8?B?TGFtaXM=?=
    Aug 29, 2007
  4. Steven D'Aprano
    Replies:
    0
    Views:
    90
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    82
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page