将 Word Excel 加载到 WPF 中

发布于 2024-08-14 08:18:01 字数 78 浏览 2 评论 0原文

我想将 Word 或 Excel 文档加载到 WPF 应用程序的窗口中,以便用户可以在应用程序中查看或编辑该文档。有什么办法可以实现这一点吗?

I would like to load a Word or Excel document into a window of a WPF application so that users can view or edit the document within the application. Is there any way to achieve that?

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

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

发布评论

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

评论(3

小瓶盖 2024-08-21 08:18:01

为了简化操作,您可以将文档打印到 Office 或 Windows(不记得是哪一个)附带的 XPS,作为名称为“Microsoft XPS Document Writer”的打印机。

获得文档后,可以使用以下视图显示该文档:

<DocumentViewer Name="docContent"/>

并且只需设置文档即可。

System.Windows.Xps.Packaging.XpsDocument doc
    = new System.Windows.Xps.Packaging.XpsDocument(
    "myDoc.xps", System.IO.FileAccess.Read);
docContent.Document = doc.GetFixedDocumentSequence();

为此,您只需引用“ReachFramework”即可。

至于编辑支持,您可以使用 XPS 规范提供的 XPS 操作策略。

To simplify things what you can do is print the document to XPS which comes with office or Windows (can't remember which) as a printer of the name "Microsoft XPS Document Writer".

Once you have the document, this can be displayed using a view of:

<DocumentViewer Name="docContent"/>

And simply set the document.

System.Windows.Xps.Packaging.XpsDocument doc
    = new System.Windows.Xps.Packaging.XpsDocument(
    "myDoc.xps", System.IO.FileAccess.Read);
docContent.Document = doc.GetFixedDocumentSequence();

For this to work you only need to reference "ReachFramework".

As for edit support you can use the XPS manipulation strategies provided by the XPS specification.

埋葬我深情 2024-08-21 08:18:01

您可以从工具箱添加 Web 浏览器控件,然后在其中加载 Word 文档。
您甚至可以打开浏览器支持的任何文档,例如 Word、Excel、PDF、SWF 等...

示例加载 Word

webBrowser1.Navigate("C:\\word.doc");

示例加载 Excel

webBrowser1.Navigate("C:\\excel.xls");

You add web browser control from toolbox and then load the Word document in it.
You can even open any document that browser support e.g. Word, Excel, PDF, SWF etc...

Example Load Word

webBrowser1.Navigate("C:\\word.doc");

Example Load Excel

webBrowser1.Navigate("C:\\excel.xls");
物价感观 2024-08-21 08:18:01

SpreadsheetGear for .NET 附带 .NET Windows 窗体控件,可以在 WPF 应用程序中轻松使用它来查看和编辑 Excel 文档。

如果您想亲自尝试,可以在此处下载免费试用版。

免责声明:我拥有 SpreadsheetGear LLC

SpreadsheetGear for .NET comes with a .NET Windows Forms control which can easily be used in WPF applications to view and edit Excel documents.

You can download a free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

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