如何使用已安装的 Office 版本在 WinForms 应用程序中查看 Microsoft Office 文档?
我正在编写一个功能,允许用户快速浏览和审阅一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在此 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.
尝试将注册表中 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.
我相信要让 Office 应用程序不显示在单独的窗口中,您必须更改该文件类型的 Windows 资源管理器文件夹设置。
来自 此 MSDN 页面:
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:
您是否考虑过将文档导出为 pdf 格式?
Have you thought about exporting the documents to pdf?