2011-07-20 53 views
0

我有一種情況,必須通過將轉發器導出到Word文檔來生成MS Word報告。我這樣做,但我的要求是將MS Word文件保存在服務器/數據庫。如何在生成Word文檔後將該文件保存在服務器/數據庫中?將轉發器導出到MS Word並保存服務器或數據庫C#上的Word文件,ASP.NET

要求是生成並將Word文件保存在服務器/數據庫上,並且生成或保存的文件也應該是隻讀文件。我該怎麼做 ?

這裏是我使用生成的Word文件中的代碼..

protected void DisplayRepeater() 
    { 
     if (ddlDivRAHQ.SelectedValue == "DIV") 
     { 
      Repeater_PrintFinalReport.DataSource = new ReportItems().Get_Rpt_Items_Div_Chief(Convert.ToInt32(Session["UserNumber"]), DateTime.Parse(Session["ReportStartDate"].ToString()), DateTime.Parse(Session["ReportEndDate"].ToString()), ddlDivRAHQ.SelectedValue.ToString()).OrderBy(x => x.OrgNum).ThenBy(x => x.Office_Location).ThenBy(x => x.Site_Desc).ToList(); 
     } 
     else 
     { 
      Repeater_PrintFinalReport.DataSource = new ReportItems().Get_Rpt_Items_Div_Chief(Convert.ToInt32(Session["UserNumber"]), DateTime.Parse(Session["ReportStartDate"].ToString()), DateTime.Parse(Session["ReportEndDate"].ToString()), ddlDivRAHQ.SelectedValue.ToString()).Where(x=>x.Finalized == 1).OrderBy(x => x.Site_Desc).ToList(); 
     } 

     Repeater_PrintFinalReport.DataBind(); 
     Repeater_PrintFinalReport.Visible = true; 
     Response.Clear(); 
     Response.AddHeader("content-disposition", "attachment;filename=" + ddlDivRAHQ.SelectedValue + "_WeeklyReport_" + DateTime.Now.ToShortDateString() + ".doc"); 
     Response.Charset = ""; 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     Response.ContentType = "application/vnd.word"; 
     System.IO.StringWriter stringWrite = new System.IO.StringWriter(); 
     System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
     Repeater_PrintFinalReport.RenderControl(htmlWrite); 
     Response.Write(stringWrite.ToString()); 
     Response.End(); 
    } 
+0

Atleast是否可以生成ReadOnly Word文件? – msbyuva

回答

-1

我已經採取了幫助從下面的鏈接

http://support.microsoft.com/kb/316384

使用Microsoft.Office MS.Word。 Interop.Word

如何通過使用Visual C來自動化Microsoft Word以創建新文檔#

+0

-1:您無法使用ASP.NET等服務器應用程序中的Office Interop。它只是不能可靠地工作,因爲這些API旨在從桌面應用程序中使用。 –

相關問題