Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi....
how to export the gridview data to msword and msexcel ...i have done it but its not supporting XML data....since i am having MSword 2007 and MS excel 2007
and this is my coding:-
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddate();
        }

    }
    private void binddate()
    {
        try
        {
            string connection = ConfigurationManager.AppSettings["ConnectInfo"];
            SqlConnection con = new SqlConnection(connection);
            SqlDataAdapter da = new SqlDataAdapter("select * from quanta", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            gv_details.DataSource = dt;
            gv_details.DataBind();

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        /* verifies the control is rendered*/

    }

    protected void btn_word_Click(object sender, ImageClickEventArgs e)
    {
        gv_details.AllowPaging = false;
        gv_details.DataBind();
        Response.ClearContent();
        Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Doc1.docx"));
            Response.Charset="";
        Response.ContentType="application/ms-word 2007";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw=new HtmlTextWriter(sw);
        gv_details.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }
}


please help me....thanks in advance...
Posted
Updated 22-Feb-12 17:26pm
v2

1 solution

try this link:-

http://forums.asp.net/t/1412788.aspx[^]

Please don't forget to mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
v2
Comments
Varun Sareen 23-Feb-12 1:33am    
[Solution Removed]: Comment from OP (Member 8405530) added:

Oh thanks a lot sir........i ll try to solve it

**Always add comment for reply to someone solution not another solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900