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. ASP.NET EXPORT TO EXCEL

ASP.NET EXPORT TO EXCEL

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettools
5 Posts 3 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.
  • M Offline
    M Offline
    Mkanchha
    wrote on last edited by
    #1

    After export gridview to excel using asp.net and vb.net Save as Type:Web Page. I want it should be Microsoft Office excel workbook My code like this ==================== gvRpt.AllowPaging = False gvRpt.GridLines = GridLines.Both Dim style As String = " .text { mso-number-format:\@; } </script> " Response.ClearContent() Response.Clear() Response.Buffer = True Response.Charset = "" Me.EnableViewState = False Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls") Response.ContentType = "application/excel" 'Response.ContentType = "application/vnd.ms-excel" Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) gvRpt.RenderControl(htw) Response.Write(style) Response.Write(sw.ToString()) Response.End()</x-turndown>

    K 1 Reply Last reply
    0
    • M Mkanchha

      After export gridview to excel using asp.net and vb.net Save as Type:Web Page. I want it should be Microsoft Office excel workbook My code like this ==================== gvRpt.AllowPaging = False gvRpt.GridLines = GridLines.Both Dim style As String = " .text { mso-number-format:\@; } </script> " Response.ClearContent() Response.Clear() Response.Buffer = True Response.Charset = "" Me.EnableViewState = False Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls") Response.ContentType = "application/excel" 'Response.ContentType = "application/vnd.ms-excel" Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) gvRpt.RenderControl(htw) Response.Write(style) Response.Write(sw.ToString()) Response.End()</x-turndown>

      K Offline
      K Offline
      Karthik Harve
      wrote on last edited by
      #2

      try below code.

      gvRpt.AllowPaging = False
      gvRpt.GridLines = GridLines.Both
      Dim style As String = " .text { mso-number-format:\@; } </script> "
      Response.ClearContent()
      Response.Clear()
      Response.Buffer = True
      Response.Charset = ""
      Me.EnableViewState = False
      Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls")
      Response.ContentType = "application/vnd.ms-excel"
      Dim sw As New StringWriter()
      Dim htw As New HtmlTextWriter(sw)
      gvRpt.RenderControl(htw)
      Response.Write(style)
      Response.Write(htw.ToString())
      Response.End()</pre>

      hope it works.
      <div class="signature">Vande Matharam - Jai Hind</div></x-turndown>

      M 1 Reply Last reply
      0
      • K Karthik Harve

        try below code.

        gvRpt.AllowPaging = False
        gvRpt.GridLines = GridLines.Both
        Dim style As String = " .text { mso-number-format:\@; } </script> "
        Response.ClearContent()
        Response.Clear()
        Response.Buffer = True
        Response.Charset = ""
        Me.EnableViewState = False
        Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls")
        Response.ContentType = "application/vnd.ms-excel"
        Dim sw As New StringWriter()
        Dim htw As New HtmlTextWriter(sw)
        gvRpt.RenderControl(htw)
        Response.Write(style)
        Response.Write(htw.ToString())
        Response.End()</pre>

        hope it works.
        <div class="signature">Vande Matharam - Jai Hind</div></x-turndown>

        M Offline
        M Offline
        Mkanchha
        wrote on last edited by
        #3

        What is the Different my code and this codde?

        B 1 Reply Last reply
        0
        • M Mkanchha

          What is the Different my code and this codde?

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Also you did not see it on the first view? Just one variable in one line was changed: Your line is: Response.Write(sw.ToString()) His line is: Response.Write(htw.ToString()) I.e. sw was replaced by htw.

          M 1 Reply Last reply
          0
          • B Bernhard Hiller

            Also you did not see it on the first view? Just one variable in one line was changed: Your line is: Response.Write(sw.ToString()) His line is: Response.Write(htw.ToString()) I.e. sw was replaced by htw.

            M Offline
            M Offline
            Mkanchha
            wrote on last edited by
            #5

            Blank Excel File generated.

            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