导出为Word用流操作

来源:互联网 发布:长沙理工网络教学 编辑:程序博客网 时间:2024/06/13 16:20

   Response.Clear();
   Response.Buffer= true;
   Response.Charset="GB2312";
   Response.AppendHeader("Content-Disposition","attachment;filename=File1.doc");
   Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
   Response.ContentType = "application/ms-word";
   
   divAll.EnableViewState=false;
   System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
   System.Web.UI.HtmlTextWriter oHtmlTextWriter1 = new System.Web.UI.HtmlTextWriter(oStringWriter);
   divAll.RenderControl(oHtmlTextWriter1);
   
   Response.Write("<table border=0  bordercolor='#FFFFFF'><tr><td>"+oStringWriter.ToString()+"</td></tr></table>");
   Response.End(); 

 

(PS:注意上面的两个DivAll那两个是层的ID.在那个页面上的东西全显示在层里面,他只打印了层里面的东西)

原创粉丝点击