开发者

How can I view Microsoft Office documents in a WinForms application using the installed version of Office?

开发者 https://www.devze.com 2023-02-08 21:50 出处:网络
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

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 com开发者_如何学Goponent, 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.


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.


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消