文章引用: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

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-03-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-03
  • 2021-12-09
  • 2021-10-09
  • 2021-12-05
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案