aspx页面导出为word

aspx页面导出为word代码:

System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(SW);
base.Form.RenderControl(htw);
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/ms-word";
Response.Charset = "gb2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode("下载") + ".doc"));

string html = sw.ToString();

Response.Write(html);
Response.Flush();
Response.Close();
posted @ 2016-07-05 17:44  liqipeng  阅读(729)  评论(0编辑  收藏  举报