2014-10-27 72 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