Opening a Word document with .doc extension with Eclipse SWT OleClientSite in Java

两盒软妹~` 提交于 2020-01-04 06:35: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.


回答1:


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



来源:https://stackoverflow.com/questions/23054905/opening-a-word-document-with-doc-extension-with-eclipse-swt-oleclientsite-in-ja

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!