Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

Export gridview to word and excel. ms word 2007 & excel 2007

Any one have the code for exporting a gridview to ms word 7.0 and excel 7.0
0
westdh
Asked:
westdh
  • 3
1 Solution
 
princeatapiCommented:
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
        Response.Charset = String.Empty;
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter sw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.RenderControl(hw);
        Response.Write(sw.ToString());
        Response.End();
    }
0
 
princeatapiCommented:
ive bounded the export with a button click event , you can relocate to any event you wish
0
 
princeatapiCommented:
fix the suitable MIME type for word export  n ths line Response.ContentType = "application/vnd.xls";
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now