2011-07-14 30 views
1

我需要在基於瀏覽器的Silverlight應用程序中顯示Office文檔。我現在所使用的解決方案涉及使用Office Automation將各種Office文檔轉換爲XPS,然後在Silverlight中使用FirstFloor Document Toolkit for Silverlight顯示生成的XPS文件。在Silverlight中顯示Office文檔

這工作,但它的速度慢,並且有相當數量的移動部件。最值得注意的是,辦公自動化部分特別不穩定,出於所有已知和明顯的原因。

我能拿出最好的選擇是購買像Aspose.Total處理文檔 - > XPS轉換件。但Aspose相當昂貴(至少在我們的場景中爲8K),主要是因爲它帶有很多我不需要的功能。如果需要,我會付出,但在此之前,我想查看是否有其他人有更好的想法。

建議如何做到這一點?基本上,我需要允許用戶將Word/Excel/Powerpoint文檔上傳到服務器,並在基於瀏覽器的Silverlight應用程序中顯示它們(只讀是正確的)。我錯過了哪些解決方案?

  • 編輯:它看起來像Electric Rain有一個PPT到XAML轉換器,用於PPT至少文件,可能是值得研究的。

  • 編輯:另一種替代FirstFloor文獻工具包看起來是PDFTron SilverDox產物。看起來它的服務器組件使用了Office自動化,但是一旦你將文檔轉換爲XPS,看起來它的客戶端Silverlight查看器就可以工作。

+0

爲什麼不只是轉換這些文檔圖像。做這樣的服務器端不應該太難。 – Denis

+0

靜態圖像可能已經足夠 - 但是我知道的唯一選項與轉換爲XPS的選項基本相同,即放入Office自動化或使用Aspose。我想知道是否有其他選擇。 –

+0

我相信有更多的提供商存在可以將Office文檔轉換爲圖像(而不是XPS)的方式。彩虹PDF例如服務器解決方案爲$ 2000 http://rainbowpdf.com/server-based-solutions/ – Denis

回答

1

我有這個問題的服務器解決方案,所以我轉換的Word文檔爲PDF編程。我現在需要在瀏覽器中調用同名的PDF文件。 (Doc1.docx到Doc1.pdf)您可以使用變量來調用文檔。這是C#後端代碼,很好地完成了這個技巧。還請記住添加對Microsoft Word 12.0對象庫的引用。調用此方法或使其成爲一個類。然後再調用文檔。

using System; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using Microsoft.Office.Interop.Word; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     ApplicationClass wordApplication = new ApplicationClass(); 
     Document wordDocument = null; 

     object paramSourceDocPath = @"D:\Websites\Docs\Doc1.docx"; 
     object paramMissing = Type.Missing; 
     string paramExportFilePath = @"D:\Websites\Docs\Doc1.pdf"; 
     WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF; 

     bool paramOpenAfterExport = false; 
     WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; 
     WdExportRange paramExportRange = WdExportRange.wdExportAllDocument; 

     int paramStartPage = 0; 
     int paramEndPage = 0; 
     WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent; 

     bool paramIncludeDocProps = true; 
     bool paramKeepIRM = true; 
     WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; 

     bool paramDocStructureTags = true; 
     bool paramBitmapMissingFonts = true; 
     bool paramUseISO19005_1 = false; 

     try 
     { 
      // Open the source document. 
      wordDocument = wordApplication.Documents.Open(
       ref paramSourceDocPath, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing, 
       ref paramMissing); 

      // Export it in the specified format. 
      if (wordDocument != null) 
       wordDocument.ExportAsFixedFormat(
        paramExportFilePath, 
        paramExportFormat, 
        paramOpenAfterExport, 
        paramExportOptimizeFor, 
        paramExportRange, 
        paramStartPage, 
        paramEndPage, 
        paramExportItem, 
        paramIncludeDocProps, 
        paramKeepIRM, 
        paramCreateBookmarks, 
        paramDocStructureTags, 
        paramBitmapMissingFonts, 
        paramUseISO19005_1, 
        ref paramMissing); 
     } 
     catch (Exception ex) 
     { 
      // Respond to the error 
     } 
     finally 
     { 
      // Close and release the Document object. 
      if (wordDocument != null) 
      { 
       wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); 
       wordDocument = null; 
      } 

      // Quit Word and release the ApplicationClass object. 
      if (wordApplication != null) 
      { 
       wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); 
       wordApplication = null; 
      } 

      GC.Collect(); 
      GC.WaitForPendingFinalizers(); 
      GC.Collect(); 
      GC.WaitForPendingFinalizers(); 
     } 
    } 
}