2014-10-27 35 views
0

我试图使用生成一个StringBuilder word文档Word文档,如下需要支持,产生使用StringBuilder的

[WebMethod] 
    public static void ExportToWord(string HTMLContent) 
    { 

     HttpContext.Current.Response.Clear(); 
     HttpContext.Current.Response.Charset = ""; 
     HttpContext.Current.Response.ContentType = "application/msword"; 
     string strFileName = "GenerateDocument" + ".doc"; 
     HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName); 
     System.Text.StringBuilder strHTMLContent = new System.Text.StringBuilder(); 
     strHTMLContent.Append(HTMLContent); 


     HttpContext.Current.Response.Write(strHTMLContent); 
     HttpContext.Current.Response.End(); 
     HttpContext.Current.Response.Flush();   
    } 

问题是,当我看到下载的文档,还增加了剩余页面内容与以上<div>内容

回答

2

我错过了Response.Clear在开始和Response.End()结束。

+0

感谢您的回复。当我使用'jquery'调用'ExportToWord()'时,我如何在这种情况下创建文档。请参阅编辑的代码。 – vallabha 2014-10-27 10:04:13