Exporting Datagrid's data to an Excel Sheet.

Discussion in 'ASP .Net' started by http://www.visual-basic-data-mining.net/forum, Oct 25, 2004.

  1. I have a web form in which I have a datagrid, I need to export this data to
    a Microsoft Excel sheet.



    I'm doing it thus:



    Response.Clear();

    Response.Buffer= true;

    Response.ContentType = "application/vnd.ms-excel";

    Response.Charset = "";

    this.EnableViewState = false;



    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
    System.Web.UI.HtmlTextWriter(oStringWriter);



    DataGrid1.RenderControl(oHtmlTextWriter);



    Response.Write(oStringWriter.ToString());

    Response.End();



    But I'd like to avoid system ask user if desires open or save this file,
    instead would open excel sheet as another window and when user saves the
    file it be saved as an excel file.



    Does somebody knows how achieve this?



    I'll appreciate it very much.

    A.L.

    --
    see07 - forum member
    http://www.visual-basic-data-mining.net/forum
     
    http://www.visual-basic-data-mining.net/forum, Oct 25, 2004
    #1
    1. Advertising

  2. This article provides a good example for you:
    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


    "http://www.visual-basic-data-mining.net/forum" <> wrote
    in message news:...
    >I have a web form in which I have a datagrid, I need to export this data to
    > a Microsoft Excel sheet.
    >
    >
    >
    > I'm doing it thus:
    >
    >
    >
    > Response.Clear();
    >
    > Response.Buffer= true;
    >
    > Response.ContentType = "application/vnd.ms-excel";
    >
    > Response.Charset = "";
    >
    > this.EnableViewState = false;
    >
    >
    >
    > System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    >
    > System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
    > System.Web.UI.HtmlTextWriter(oStringWriter);
    >
    >
    >
    > DataGrid1.RenderControl(oHtmlTextWriter);
    >
    >
    >
    > Response.Write(oStringWriter.ToString());
    >
    > Response.End();
    >
    >
    >
    > But I'd like to avoid system ask user if desires open or save this file,
    > instead would open excel sheet as another window and when user saves the
    > file it be saved as an excel file.
    >
    >
    >
    > Does somebody knows how achieve this?
    >
    >
    >
    > I'll appreciate it very much.
    >
    > A.L.
    >
    > --
    > see07 - forum member
    > http://www.visual-basic-data-mining.net/forum
    >
    >
     
    Steve C. Orr [MVP, MCSD], Oct 25, 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. =?Utf-8?B?U2lsZWVzaA==?=
    Replies:
    4
    Views:
    414
    =?Utf-8?B?U2lsZWVzaA==?=
    Nov 5, 2004
  2. =?Utf-8?B?U2lsZWVzaA==?=
    Replies:
    1
    Views:
    739
    Jim Corey
    Nov 8, 2004
  3. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,405
    Carl Prothman [MVP]
    Jan 12, 2005
  4. =?Utf-8?B?U3JpZGhhcg==?=

    change the sheet name while exporting datagrid data to excel

    =?Utf-8?B?U3JpZGhhcg==?=, Nov 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    543
    =?Utf-8?B?U3JpZGhhcg==?=
    Nov 9, 2006
  5. AD1234
    Replies:
    5
    Views:
    1,681
Loading...

Share This Page