asp.net网页内容导出到word

文章引用:http://topic.csdn.net/t/20040909/15/3356495.html

把网页内容 导出到到word中后改变了 内容的显示方式 :

public void ToWord(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=DocLibrary.doc");

HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//更改ContentType的值为ms-word即可实现导出到Word
HttpContext.Current.Response.ContentType = "application/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}



调用方式:ToWord(this.divTest);   //注:divTest是控件的id

posted @ 2011-10-05 10:07  Credo Chen  阅读(1510)  评论(2编辑  收藏  举报
无觅相关文章插件,快速提升流量