ASP.NET DataGrid and Excel

Discussion in 'ASP .Net Datagrid Control' started by Milan Todorovic, Nov 24, 2003.

  1. I desperately need help.

    I have an ASP.NET (in VB.NET) app that displays the data within the datagrid
    object. I need to allow for exporting of that data to the Excel spreadsheet.
    I have tried using Excel (referenced) object, but for some reason I can't
    get it to work. I get all sorts of COM errors.
    I'm looking for the simplest solution, since I do not care about any Excel
    formatting or functionalities.

    Thanks

    Milan Todorovic
     
    Milan Todorovic, Nov 24, 2003
    #1
    1. Advertising

  2. Milan Todorovic

    Alvin Bruney Guest

    The easiest solution here would be dump the datagrid out as a csv or html
    file to disk. Then, load the file into the spreadsheet using the csvdata or
    htmdata property of the spreadsheet object.

    Regards

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Milan Todorovic" <> wrote in message
    news:...
    > I desperately need help.
    >
    > I have an ASP.NET (in VB.NET) app that displays the data within the

    datagrid
    > object. I need to allow for exporting of that data to the Excel

    spreadsheet.
    > I have tried using Excel (referenced) object, but for some reason I can't
    > get it to work. I get all sorts of COM errors.
    > I'm looking for the simplest solution, since I do not care about any Excel
    > formatting or functionalities.
    >
    > Thanks
    >
    > Milan Todorovic
    >
    >
     
    Alvin Bruney, Nov 24, 2003
    #2
    1. Advertising

  3. "Milan Todorovic" <> wrote in message
    news:...
    > I desperately need help.
    >
    > I have an ASP.NET (in VB.NET) app that displays the data within the

    datagrid
    > object. I need to allow for exporting of that data to the Excel

    spreadsheet.
    > I have tried using Excel (referenced) object, but for some reason I can't
    > get it to work. I get all sorts of COM errors.
    > I'm looking for the simplest solution, since I do not care about any Excel
    > formatting or functionalities.


    Here's what we did. Offer a pop-up window from your page to return the data
    as Excel. In the asp.net page for the popup, render the same datatable to a
    datagrid, and return the page with the Response.ContentType MIME type set to
    'application/x-msexcel'

    R.
     
    Richard K Bethell, Nov 24, 2003
    #3
  4. Richard,
    That was actually the advice I was hoping for.
    Now, I have a question or two about this approach. Apparently, if you create
    xls file by using Response.ContentType = "application.x-msexcel" the
    spreadsheet fails to open, due to the presence of the datagrid object (i.e.
    if the datagrid is not there it works fine). However, I could use the
    datatable (datagrid source) and build html table that I can stream into
    response object. The question I have is this: is it possible (if yes, how)
    to accomplish this without creating the new page (which would create a clean
    Response object). That is, is it possible to use the Response object of the
    existing page?
    I'll keep on researching this idea.
    Thanks for the pointer
    Milan


    "Richard K Bethell" <> wrote in message
    news:...
    > "Milan Todorovic" <> wrote in message
    > news:...
    > > I desperately need help.
    > >
    > > I have an ASP.NET (in VB.NET) app that displays the data within the

    > datagrid
    > > object. I need to allow for exporting of that data to the Excel

    > spreadsheet.
    > > I have tried using Excel (referenced) object, but for some reason I

    can't
    > > get it to work. I get all sorts of COM errors.
    > > I'm looking for the simplest solution, since I do not care about any

    Excel
    > > formatting or functionalities.

    >
    > Here's what we did. Offer a pop-up window from your page to return the

    data
    > as Excel. In the asp.net page for the popup, render the same datatable to

    a
    > datagrid, and return the page with the Response.ContentType MIME type set

    to
    > 'application/x-msexcel'
    >
    > R.
    >
    >
     
    Milan Todorovic, Nov 24, 2003
    #4
  5. Milan Todorovic

    Jack Mullins Guest

    Here is some code I found and have tried with success
    objAdapter.SelectCommand = New OleDbCommand(strSQL, objConn

    objAdapter.Fill(objDataset
    ' Create a new view
    Dim oView As New DataView(objDataset.Tables(0)
    ' Set up the data grid and bind the data
    DataGrid1.DataSource = oVie
    DataGrid1.DataBind(

    ' Verify if the page is to be displayed in Excel
    If Request.QueryString("bExcel") = "1" The
    ' 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

    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChange

    End Su
    End Clas
     
    Jack Mullins, Nov 26, 2003
    #5
    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. Anonieko
    Replies:
    2
    Views:
    7,365
    JackStraw73
    Feb 12, 2008
  2. Robbe Morris [C# MVP]

    asp.net extracting excel charts from an Excel file

    Robbe Morris [C# MVP], Dec 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    503
    Robbe Morris [C# MVP]
    Dec 15, 2006
  3. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,596
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  4. Grey
    Replies:
    4
    Views:
    2,107
    Mark Rae [MVP]
    Oct 17, 2007
  5. fniles
    Replies:
    6
    Views:
    681
    Karl E. Peterson
    Apr 27, 2009
Loading...

Share This Page