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 Word

Export GridView to Word

Scheduled Pinned Locked Moved ASP.NET
designhelptutorial
2 Posts 2 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.
  • R Offline
    R Offline
    RadioButton
    wrote on last edited by
    #1

    Hello, I am using the basic export to Word code for my GridView below. I am trying to figure out how to remove the hidden input field that gets added to the output from the StringWriter. Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=TheFile" + FileDateTime("doc")); Response.Buffer = true; Response.ContentType = "application/vnd.word"; Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); HtmlForm fakeForm = new HtmlForm(); this.Controls.Add(fakeForm); fakeForm.Controls.Add(gvMine); fakeForm.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Thanks for the help. RB

    M 1 Reply Last reply
    0
    • R RadioButton

      Hello, I am using the basic export to Word code for my GridView below. I am trying to figure out how to remove the hidden input field that gets added to the output from the StringWriter. Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=TheFile" + FileDateTime("doc")); Response.Buffer = true; Response.ContentType = "application/vnd.word"; Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); HtmlForm fakeForm = new HtmlForm(); this.Controls.Add(fakeForm); fakeForm.Controls.Add(gvMine); fakeForm.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Thanks for the help. RB

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      You can use the regular expression with the Regex class to get rid of the hidden html markup in the output result (oStringWriter.ToString()) before sending out to the output stream of the Response object.

      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