Thursday, 6 September 2012

Generate and Export a word document using the content from a div element

strFileName = "<Documentname>.doc";
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Charset = "";
                    HttpContext.Current.Response.ContentType = "application/msword";

                    HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter w = new HtmlTextWriter(sw);

//following “divElement” is the id of the div tag

                    divElement.RenderControl(w);

                    string s = sw.GetStringBuilder().ToString();




                    HttpContext.Current.Response.Write(s);

No comments:

Post a Comment