如何使用已安装的 Office 版本在 WinForms 应用程序中查看 Microsoft Office 文档?

发布于 2024-10-16 10:22:33 字数 594 浏览 2 评论 0原文

我正在编写一个功能,允许用户快速浏览和审阅一些 Word 文档。所有用户都将安装 Office 2003、2007 或 2010(这是某些其他功能所必需的)。文档(其中大部分是 Word)只需以只读方式显示即可。

我尝试使用 MSDN 上的示例,其中将 Office 文档加载到网络浏览器中组件,使用 VS2008 和 Office 2007。Excel

电子表格加载得相当好,但 Word 文档出现在单独的窗口中,尽管没有工具栏仅显示文档正文。微软似乎也已经停止支持这种渲染 Office 文档的方式,因为该文章自 2007 年以来就没有更新过。

任何人都可以建议如何让这种方式成功工作吗?

我还查看了第三方组件,例如 aspose.net 看起来不错,但许可费相当高,考虑到所有用户都已经安装了 Office,这似乎有点过分了。

I'm writing a feature to allow users to quickly skim through and review a number of word documents fairly quickly. All users will have either Office 2003, 2007 or 2010 installed (this is required for some other features). The documents (the majority of which will be Word) just need to be displayed read only.

I've tried using the example on MSDN, where the office document is loaded into a web browser component, using VS2008 and Office 2007.

Excel spreadsheets loaded reasonably well, but Word documents appeared in a separate Window, albeit with no toolbars showing only the body of the document. It also seems that Microsoft have stopped supporting this way of rendering office documents as the article hasn't been updated since 2007.

Can anyone advise on how to get this working successfully?

I've also had a look at third party components such as aspose.net which look great, but the license fee is pretty big and seems like overkill considering all users will have Office installed already.

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

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

发布评论

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

评论(4

桃扇骨 2024-10-23 10:22:33

我在此 msdn 论坛< /a>.

问题是我使用的测试 .NET 项目是作为“任何 CPU”构建的,它在 64 位 Windows 上作为 64 位进程运行。

我安装了 32 位版本的 Office 2007。

将 .NET 项目配置更改为 x86,WebBrowser 组件能够在其自己的窗口中托管 Word 文档。

我仍然不明白为什么 Excel 即使在作为任何 CPU 运行时也能够加载到 Web 浏览器中。

I found the solution on this msdn forum.

The problem was that the test .NET project I was using was built as "Any CPU", which runs as a 64-bit process on 64-bit Windows.

I have the 32-bit version of Office 2007 installed.

Changing the .NET project configuration to x86, the WebBrowser component was able to host the Word documents in it's own window.

I still don't understand why Excel was able to load in the WebBrowser even when running as Any CPU.

心房的律动 2024-10-23 10:22:33

尝试将注册表中 HKCR\Word.Document.12 和 HKCR\Word.Document.8 下的 BrowserFlags 设置为 0x80000024。

有关详细信息,请参阅 http://support.microsoft.com/kb/982995

Try setting the BrowserFlags in the registry under HKCR\Word.Document.12 and HKCR\Word.Document.8 to 0x80000024.

See http://support.microsoft.com/kb/982995 for more information.

瑶笙 2024-10-23 10:22:33

我相信要让 Office 应用程序不显示在单独的窗口中,您必须更改该文件类型的 Windows 资源管理器文件夹设置。

来自 此 MSDN 页面

Internet Explorer 使用在同一窗口中浏览选项来确定文档是托管在活动窗口还是单独的窗口内。如果文档托管在单独的窗口中,则不会加载和运行自定义内容。要访问 Word 文档或 Excel 工作表的在同一窗口中浏览选项,请打开 Windows 资源管理器,单击工具菜单,然后单击文件夹选项强>。在文件类型选项卡上,在文件类型列表中选择DOCXLS,单击高级,然后验证已选择在同一窗口中浏览

I believe to get the Office applications to not show up in a separate window, you have to change a Windows Explorer folder setting for that file type.

From this MSDN page:

The Browse in same window option is used by Internet Explorer to determine whether the document is hosted inside the active window or a separate window. If the document is hosted in a separate window, the customizations do not load and run. To access the Browse in same window option for a Word document or an Excel worksheet, open Windows Explorer, click the Tools menu, and then click Folder Options. On the File Types tab, select DOC or XLS in the list of file types, click Advanced, and verify that Browse in same window is selected.

狼性发作 2024-10-23 10:22:33

您是否考虑过将文档导出为 pdf 格式?

  • 免费的 Adob​​e-reader
  • 只读
  • 可以在需要时保存以供以后查看
  • 可以打印

Have you thought about exporting the documents to pdf?

  • Free Adobe-reader
  • Read-only
  • Possibility to save if needed for later review
  • Possibilty to print
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文