How to view Microsoft Office documents in WinForms using the installed version of Office?

I am writing a feature that allows users to quickly view and analyze multiple text documents quite quickly. All users will have Office 2003, 2007, or 2010 installed (this is required for some other features). Documents (most of which will be Word) just have to be read-only.

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

Excel spreadsheets are loaded quite well, but Word documents appeared in a separate window, although without toolbars showing only the body of the document. It also seems that Microsoft has ceased to support this way of providing office documents, as the article has not been updated since 2007.

Can anyone advise how this works successfully?

I also looked at third-party components, such as aspose.net , that look great, but the license fee is quite large and seems to overflow, given that all users have already installed Office.

+4
source share
4 answers

I found a solution on this msdn forum .

The problem was that the .NET test project that I used was built as “Any processor” that works like a 64-bit process on 64-bit Windows.

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

By changing the configuration of the .NET project to x86, the WebBrowser component was able to place Word documents in its own window.

I still do not understand why Excel was able to load into WebBrowser even when working as any processor.

+6
source

Try installing 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 details.

+2
source

I believe that Office applications do not appear in a separate window, you need to change the settings of the Windows Explorer folder for this type of file.

From this MSDN page :

The Browse option in the same window is used by Internet Explorer to determine if the document is placed inside the active window or in a separate window. If the document is placed in a separate window, the settings do not load and do not start. To open the Browse option in the same window for a Word document or Excel sheet, open Windows Explorer, open the Tools menu and click Folder Options . On the File Types tab , select DOC or XLS in the list of file types, click Advanced and check that Browse is in the same window .

+1
source

Have you thought about exporting documents to pdf?

  • Free Adobe-reader
  • only for reading
  • The ability to save if necessary for later viewing
  • Ability to print
0
source

Source: https://habr.com/ru/post/1338767/


All Articles