C# – How to view Microsoft Office documents in a WinForms application using the installed version of Office

cms-officewinforms

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.

Best Answer

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.

Related Topic