Question : 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

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

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();
    }
Random Solutions  
 
programming4us programming4us