日期:2014-05-17  浏览次数:20380 次

请问如何将页面内所有内容生成WORD并下载
我的页面是一个表单页面,包括很多TEXTBOX和radiobuttonlist,还有很多没写在控件内的标题,请问如何将全部内容生成WORD并下载,谢谢

------解决方案--------------------
将你要输出的内容放在asp:panel标签内,

代码如下:
C# code

StringWriter tw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(tw);
                this.pan_content.RenderControl(hw);
                           
                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                response.ContentType ="application/vnd.ms-word"; 

                response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode(Server.UrlDecode(this.lbtitle.Text) + ".doc"));
                //response.Charset = "utf-8";
                response.Write(tw.ToString());
                response.End();

------解决方案--------------------
加一个方法:
C# code

public override void VerifyRenderingInServerForm(Control control)
  {
  //base.VerifyRenderingInServerForm(control);  
  }