Thursday, August 30, 2012

Export gridview data to Word using asp.net using C#

Here i will explain How to Export Gridview Data To Word. While Exporting I will explain the problems how to solve them. First download the ItextSharp from the above link.

Previously Explained 

  • Export Gridview Data To PDF          ClickHere 
  • Export Gridview Data To Excel        ClickHere 

 And Now i will Explain As the Title Says

         protected void btnExpToWord_Click(object sender, EventArgs e)
        {
            try
            {
                ExpGvToExcelControl.AllowPaging = false;
                BindGrid();
                Response.ClearContent();
                Response.AddHeader("content-disposition", 

                             string.Format("attachment; filename={0}", "EmpInfo.doc"));
                Response.Charset = "";
                Response.ContentType = "application/ms-word";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                ExpGvToExcelControl.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
            }
            catch (Exception ex)
            {
                string ErrMsg = ex.Message;
            }
        }








No comments:

Post a Comment