将网页到出word文档,全面兼容所有office版本的代码

解决方案 »

  1.   

    public void ExpertControl(System.Web.UI.Control source, DocumentType type)        {
                if (type == DocumentType.Excel)
                {
                    Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
                    Response.ContentType = "application/ms-excel";
                }
                else if (type == DocumentType.Word)
                {
                    Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
                    Response.ContentType = "application/ms-word";
                }
                Response.Charset = "utf-8";   
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                source.Page.EnableViewState =false;   
                System.IO.StringWriter writer = new System.IO.StringWriter() ;
                System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
                source.RenderControl(htmlWriter);
                Response.Write(writer.ToString());
                Response.End();
            }
            public enum DocumentType
            {
                Word,
                Excel
            }
    参考
    参考
      

  2.   

    http://topic.csdn.net/t/20060326/21/4641413.html