在 Silverlight 中显示 Office 文档

发布于 2024-11-24 02:07:45 字数 1087 浏览 9 评论 0原文

我需要在基于浏览器的 Silverlight 应用程序中显示 Office 文档。我现在采用的解决方案涉及使用 Office Automation 将各种 Office 文档转换为 XPS,然后使用 用于 Silverlight 的 FirstFloor 文档工具包

这可行,但速度很慢,并且有相当多的移动部件。最值得注意的是,由于所有已知和明显的原因,办公自动化部分特别不稳定。

我能想到的最好的选择是购买类似 Aspose.Total 来处理文档->XPS 转换块。但 Aspose 相当昂贵(对于我们的场景来说至少是 8K 美元),主要是因为它附带了很多我并不真正需要的功能。如果有必要的话我会付钱,但在付钱之前,我想看看其他人是否有更好的想法。

关于如何实现这一目标的建议?基本上,我需要允许用户将 Word/Excel/Powerpoint 文档上传到服务器,并在基于浏览器的 Silverlight 应用程序中显示它们(只读即可)。有什么我错过的解决方案吗?

  • 编辑:看起来Electric Rain有一个PPT到XAML转换器,可以至少值得研究 PPT 文件。

  • 编辑:FirstFloor Document Toolkit 的另一个替代品似乎是 PDFTron SilverDox 产品。看起来它的服务器组件使用 Office Automation,但是一旦您将文档导入 XPS,它的客户端 Silverlight 查看器似乎就可以工作了。

I've got a need to display Office documents in a browser-based Silverlight application. The solution that I've got in place right now involves using Office Automation to convert the various Office docs to XPS, and then displaying the resulting XPS files in Silverlight with the FirstFloor Document Toolkit for Silverlight.

This works, but it's slow, and has a fair number of moving parts. Most notably, the Office Automation piece is particularly unstable, for all the known and obvious reasons.

The best alternative I can come up with is to purchase something like Aspose.Total to handle the document->XPS conversion piece. But Aspose is fairly expensive (at least $8K for our scenario), largely because it comes with a lot of functionality that I don't really need. I'll pay that if I have to, but before I do, I want to check to see if anyone else has any better ideas.

Suggestions on how to accomplish this? Basically, I need to allow users to upload Word/Excel/Powerpoint docs to a server, and display them (read-only is fine) in a browser-based Silverlight application. Any solutions out there that I've missed?

  • Edit: It looks like Electric Rain has a PPT-to-XAML converter that might be worth investigating for PPT files at least.

  • Edit: Another alternative to the FirstFloor Document Toolkit looks to be the PDFTron SilverDox product. It looks like its server component uses Office Automation, but once you get the doc into XPS, it looks like its client-side Silverlight viewer would work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

去了角落 2024-12-01 02:07:45

Rainbow PDF 提供服务器解决方案,售价 2000 美元 http://rainbowpdf.com/server-based-solutions

: )

Rainbow PDF has server solution for $2000 http://rainbowpdf.com/server-based-solutions

:)

因为看清所以看轻 2024-12-01 02:07:45

我遇到了这个问题,所以我以编程方式将 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();
        }
    }
}

I had this issue, so I converted the Word Docs to PDF programatically. I now need to call the same name PDF file in the browser. (Doc1.docx to Doc1.pdf) You can use variables to call the documents. This is C# backend code that does the trick nicely. Also remember to add the reference to the Microsoft Word 12.0 Object Library. Call this method or make it a class. Then call the document after that.

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();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文