Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. export gridview to excel in asp.net

export gridview to excel in asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jadhavShubhangi
    wrote on last edited by
    #1

    hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot

    B V 2 Replies Last reply
    0
    • J jadhavShubhangi

      hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      jadhavshubhangi wrote:

      It gives gridview in excel but not a normal excel file..........

      What do you mean by this? Not a normal excel file, what is the problem? there is a lot of code snippet available on google. Have a look

      Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0

      J 1 Reply Last reply
      0
      • B Brij

        jadhavshubhangi wrote:

        It gives gridview in excel but not a normal excel file..........

        What do you mean by this? Not a normal excel file, what is the problem? there is a lot of code snippet available on google. Have a look

        Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0

        J Offline
        J Offline
        jadhavShubhangi
        wrote on last edited by
        #3

        thanks for reply This excel sheet is not regular format like rows and columns only show gridview. Thanks

        N 1 Reply Last reply
        0
        • J jadhavShubhangi

          thanks for reply This excel sheet is not regular format like rows and columns only show gridview. Thanks

          N Offline
          N Offline
          nagendrathecoder
          wrote on last edited by
          #4

          What is the extension of file you are getting? If its .xls then it is excel format. The gridlines might not be visible there, you have to add gridlines.

          1 Reply Last reply
          0
          • J jadhavShubhangi

            hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot

            V Offline
            V Offline
            Venkatesh Mookkan
            wrote on last edited by
            #5

            Actually you are saving HTML as Excel. That excel only shows the Grid's Gridlines. You can set gridlines manually by opening the excel. Or write a ActiveX to generate original excel using the Grid's data.

            Castle Rider

            What if I freeze??? Don't forget to breath...

            My: Website | Yahoo Group | Blog Spot

            /xml>

            J 1 Reply Last reply
            0
            • V Venkatesh Mookkan

              Actually you are saving HTML as Excel. That excel only shows the Grid's Gridlines. You can set gridlines manually by opening the excel. Or write a ActiveX to generate original excel using the Grid's data.

              Castle Rider

              What if I freeze??? Don't forget to breath...

              My: Website | Yahoo Group | Blog Spot

              /xml>

              J Offline
              J Offline
              jadhavShubhangi
              wrote on last edited by
              #6

              thanks for reply

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups