Opening a Word document with .doc extension with E

2019-07-16 19:37发布

I'm working on a program that uses the Eclipse SWT OleClientSite (in Windows 7) to open a Word document inside an RCP application. For the past two years, this program has called the following constructor:

OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NULL, new File(documentFileName));

Since the latest update to SWT, this constructor now throws an exception when attempting to open Word documents with a ".doc" extension. Word documents with a ".docx" extension are still functioning correctly. The problem seems to be that OleClientSite isn't properly recognizing ".doc" as a Word extension, since explicitly inputting this information with the following constructor works:

OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NULL, "Word.Document", new File(documentFileName));

This constructor comes with a warning, however, stating that it is never to be used:

IMPORTANT:This method is not part of the public API for OleClientSite. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

Oddly enough, even though this constructor explicitly says it should never be used, it is used on the Eclipse SWT Snippets Website as an example of how to open a .doc file...

If anyone has any pointers, I'd greatly appreciate it. So far my options seem to be either to forbid my users from using ".doc" files or to roll back to an old version of SWT.

标签: java swt ole
1条回答
【Aperson】
2楼-- · 2019-07-16 19:56

The current Eclipse version supports opening a Word-Document (*.doc) from the navigator view. It uses the class org.eclipse.ui.internal.editorsupport.win32.OleEditor to open the document in an Editor-Part. I would suggest, you take a look at the code at [1] and adapt the needed parts to your scenario.

[1] http://git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/bundles/org.eclipse.ui.win32/src/org/eclipse/ui/internal/editorsupport/win32/OleEditor.java

查看更多
登录 后发表回答