Export data to Excel

Discussion in 'ASP .Net' started by Grey, Jan 9, 2004.

  1. Grey

    Grey Guest

    is it possible to export excel directly from ASP.NET to Excel? My requirement is that the data on the datagrid is exported to MS Excel file after user clicks the button on the web page. Excel will be open automatically with imported data. If so, is need to add any additional controls or tools?


    Million Thanks..

    Eric Yum
     
    Grey, Jan 9, 2004
    #1
    1. Advertising

  2. Grey

    BruceJohnson Guest

    BruceJohnson, Jan 9, 2004
    #2
    1. Advertising

  3. Grey

    Glenn Guest

    There is a third party tool called ExcelWriter that allows
    you to easily create spreadsheets without having Excel
    installed on the server. It is very quick and easy to
    use... check it out at www.softartisans.com.

    It is a COM component but they have class wrappers that
    allow you to use it in .NET. The latest version lets you
    create spreadsheet content by binding a DataSet (previous
    versions only support ADO recordset binding - you have to
    create the rows manually).

    Cheers,

    Glenn.

    >-----Original Message-----
    >is it possible to export excel directly from ASP.NET to

    Excel? My requirement is that the data on the datagrid is
    exported to MS Excel file after user clicks the button on
    the web page. Excel will be open automatically with
    imported data. If so, is need to add any additional
    controls or tools?
    >
    >
    >Million Thanks..
    >
    >Eric Yum
    >
     
    Glenn, Jan 9, 2004
    #3
  4. This article gives a number of possible solutions:
    http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

    And here's another technique that might work for you:
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q306572

    And these 3rd party components are of high quality:
    http://www.aspose.com/Products/Aspose.Excel/
    http://officewriter.softartisans.com/

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



    "Grey" <> wrote in message news:%...
    is it possible to export excel directly from ASP.NET to Excel? My requirement is that the data on the datagrid is exported to MS Excel file after user clicks the button on the web page. Excel will be open automatically with imported data. If so, is need to add any additional controls or tools?


    Million Thanks..

    Eric Yum
     
    Steve C. Orr [MVP, MCSD], Jan 9, 2004
    #4
  5. I have looked high and low for a simple solution to export a DataGrid to MS Excel in ASP.NET. I weeded out this code from Microsoft support. Simply create a button called ExportToExcel and place this code in the Click event and rename DataGrid1 in the code to whatever your datagrid is called. When you run the page and click your button you will be prompted to open excel in ie or save whatever data is in your datagrid to an excel file of your choice. I hope this saves beginner programmers such as myself some time and effort

    sub ExportToExcel_Click(sender As Object, e As EventArgs

    ' Set the content type to Excel
    Response.ContentType = "application/vnd.ms-excel
    ' Remove the charset from the Content-Type header
    Response.Charset = "
    ' Turn off the view state
    Me.EnableViewState = Fals

    Dim tw As New System.IO.StringWriter(
    Dim hw As New System.Web.UI.HtmlTextWriter(tw
    ' Get the HTML for the control
    DataGrid1.RenderControl(hw
    ' Write the HTML back to the browser
    Response.Write(tw.ToString()
    ' End the response
    Response.End(
    End I

    End Su
     
    =?Utf-8?B?cGRtMg==?=, Apr 3, 2004
    #5
  6. I have looked high and low for a simple solution to export a DataGrid to MS Excel in ASP.NET. I weeded out this code from Microsoft support. Simply create a button called ExportToExcel and place this code in the Click event and rename DataGrid1 in the code to whatever your datagrid is called. When you run the page and click your button you will be prompted to open excel in ie or save whatever data is in your datagrid to an excel file of your choice. I hope this saves beginner programmers such as myself some time and effort

    sub ExportToExcel_Click(sender As Object, e As EventArgs

    ' Set the content type to Excel
    Response.ContentType = "application/vnd.ms-excel
    ' Remove the charset from the Content-Type header
    Response.Charset = "
    ' Turn off the view state
    Me.EnableViewState = Fals

    Dim tw As New System.IO.StringWriter(
    Dim hw As New System.Web.UI.HtmlTextWriter(tw
    ' Get the HTML for the control
    DataGrid1.RenderControl(hw
    ' Write the HTML back to the browser
    Response.Write(tw.ToString()
    ' End the response
    Response.End(
    End I

    End Su
     
    =?Utf-8?B?cGRtMg==?=, Apr 3, 2004
    #6
    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. Deva

    Export data from grid to Excel

    Deva, Jan 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,356
  2. Joy
    Replies:
    2
    Views:
    2,676
    Sabre
    Aug 22, 2003
  3. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,135
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  4. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Export to Excel (Default File Type - Excel)

    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    15
    Views:
    17,580
    syed hassan
    May 21, 2009
  5. Grey
    Replies:
    4
    Views:
    2,045
    Mark Rae [MVP]
    Oct 17, 2007
Loading...

Share This Page