Exporting to Excel directly from ObjectDataSource?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ASF

    #1

    Exporting to Excel directly from ObjectDataSource?

    Hey all,
    I have a gridview with an objectdatasourc e. I've been using the below
    code to export to excel:

    gvITV.AllowSort ing = False
    gvITV.DataBind( )
    Dim tw As New IO.StringWriter ()
    Dim hw As New System.Web.UI.H tmlTextWriter(t w)
    Dim frm As HtmlForm = New HtmlForm()
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der("content-disposition",
    "attachment;fil ename=export.xl s")
    Response.Charse t = ""
    EnableViewState = False
    Controls.Add(fr m)
    frm.Controls.Ad d(gvITV)
    frm.RenderContr ol(hw)
    Response.Write( tw.ToString())
    Response.End()
    gvITV.AllowSort ing = True
    gvITV.DataBind( )

    However, I dislike that I have to pull from the Gridview at all. I
    should be able to skip the gridview binding and pull directly from the
    objectdatasourc e, but I haven't been able to discover a way to do
    this. Does anyone have any suggestions?
  • Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

    #2
    Re: Exporting to Excel directly from ObjectDataSourc e?

    I've documented a number of ways to export data to Excel:
    Find information, resources and relevant links for steveorr.net. This domain may be for sale.

    Find information, resources and relevant links for steveorr.net. This domain may be for sale.


    If your needs turn out to be more advanced, you might want to invest in a
    good 3rd party component such as one of these:
    Find information, resources and relevant links for steveorr.net. This domain may be for sale.

    Find information, resources and relevant links for steveorr.net. This domain may be for sale.


    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    Find information, resources and relevant links for steveorr.net. This domain may be for sale.





    "ASF" <roy.anderson@g mail.comwrote in message
    news:c73ec384-b7c7-44a9-81af-e2ac82cb8b77@z6 6g2000hsc.googl egroups.com...
    Hey all,
    I have a gridview with an objectdatasourc e. I've been using the below
    code to export to excel:
    >
    gvITV.AllowSort ing = False
    gvITV.DataBind( )
    Dim tw As New IO.StringWriter ()
    Dim hw As New System.Web.UI.H tmlTextWriter(t w)
    Dim frm As HtmlForm = New HtmlForm()
    Response.Conten tType = "applicatio n/vnd.ms-excel"
    Response.AddHea der("content-disposition",
    "attachment;fil ename=export.xl s")
    Response.Charse t = ""
    EnableViewState = False
    Controls.Add(fr m)
    frm.Controls.Ad d(gvITV)
    frm.RenderContr ol(hw)
    Response.Write( tw.ToString())
    Response.End()
    gvITV.AllowSort ing = True
    gvITV.DataBind( )
    >
    However, I dislike that I have to pull from the Gridview at all. I
    should be able to skip the gridview binding and pull directly from the
    objectdatasourc e, but I haven't been able to discover a way to do
    this. Does anyone have any suggestions?

    Comment

    • ASF

      #3
      Re: Exporting to Excel directly from ObjectDataSourc e?

      Hi Steve,

      Your articles are informative, but you may have misunderstood my
      question. I want to pull directly from the objectdatasourc e to excel
      but I haven't discerned how to access the ODS datatable in the
      codebehind. Thoughts?

      Thanks



      On Jun 20, 9:29 pm, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]"
      <St...@Orr.netw rote:
      I've documented a number of ways to export data to Excel:http://SteveOrr.net/articles/ExcelEx...portPanel.aspx
      >
      If your needs turn out to be more advanced, you might want to invest in a
      good 3rd party component such as one of these:http://SteveOrr.net/reviews/AsposeEx...iceWriter.aspx
      >
      --
      I hope this helps,
      Steve C. Orr,
      MCSD, MVP, CSM, ASPInsiderhttp://SteveOrr.nethtt p://iPhonePlaza.net
      >
      "ASF" <roy.ander...@g mail.comwrote in message
      >
      >
      >
      Hey all,
      I have a gridview with an objectdatasourc e. I've been using the below
      code to export to excel:
      >
                 gvITV.AllowSort ing = False
                 gvITV.DataBind( )
                 Dim tw As New IO.StringWriter ()
                 Dim hw As New System.Web.UI.H tmlTextWriter(t w)
                 Dim frm As HtmlForm = New HtmlForm()
                 Response.Conten tType = "applicatio n/vnd.ms-excel"
                 Response.AddHea der("content-disposition",
      "attachment;fil ename=export.xl s")
                 Response.Charse t = ""
                 EnableViewState = False
                 Controls.Add(fr m)
                 frm.Controls.Ad d(gvITV)
                 frm.RenderContr ol(hw)
                 Response.Write( tw.ToString())
                 Response.End()
                 gvITV.AllowSort ing = True
                 gvITV.DataBind( )
      >
      However, I dislike that I have to pull from the Gridview at all. I
      should be able to skip the gridview binding and pull directly from the
      objectdatasourc e, but I haven't been able to discover a way to do
      this. Does anyone have any suggestions?

      Comment

      Working...