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

12,443

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
12,443
StrayPointer
Author by

StrayPointer

Developer Manager based in London, UK. LinkedIn profile

Updated on June 18, 2022

Comments

  • StrayPointer
    StrayPointer almost 2 years

    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.

  • StrayPointer
    StrayPointer about 13 years
    Unfortunately this option no longer exists in Windows 7. I tried changing the BrowserFlags registry settings as well but unfortunately this did not have any effect with Office 2007 either
  • StrayPointer
    StrayPointer about 13 years
    As I've answered below-the issue on my machine was due to trying to load the 32-bit word document in a 64-bit web browser component. These registry settings still look helpful - thanks for the info!
  • StrayPointer
    StrayPointer about 13 years
    Have you any suggestions how to display a pdf document in a WinForms application?