页面中的内容输出到word,并下载

将你要输出的内容放在asp:panel标签内,

 

StringWriter tw =new StringWriter(); HtmlTextWriter hw =new HtmlTextWriter(tw); this.pan_content.RenderControl(hw); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.Clear(); response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); response.ContentType ="application/vnd.ms-word"; response.AddHeader("Content-Disposition", "attachment; filename="+ Server.UrlPathEncode(Server.UrlDecode(this.lbtitle.Text) +".doc")); //response.Charset = "utf-8"; response.Write(tw.ToString()); response.End();
原文地址:https://www.cnblogs.com/blackbean/p/2678385.html