使用Java中的Eclipse SWT OleClientSite打开扩展名为.doc的Word文档 [英] Opening a Word document with .doc extension with Eclipse SWT OleClientSite in Java

查看:372
本文介绍了使用Java中的Eclipse SWT OleClientSite打开扩展名为.doc的Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Eclipse SWT OleClientSite(在Windows 7中)在RCP应用程序内部打开Word文档的程序.在过去的两年中,该程序调用了以下构造函数:

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));

自从SWT的最新更新以来,此构造函数现在在尝试打开扩展名为".doc"的Word文档时引发异常.带有".docx"扩展名的Word文档仍然可以正常运行.问题似乎是OleClientSite无法正确地将".doc"识别为Word扩展名,因为使用以下构造函数显式输入此信息是可行的:

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:

重要提示:此方法不属于公众 OleClientSite的API.仅将其标记为公开,以便它 可以在SWT提供的程序包中共享.它不是 在所有平台上都可用,并且绝对不能从 应用程序代码.

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...

如果有人有任何指针,我将不胜感激.到目前为止,我的选择似乎是禁止用户使用".doc"文件,或者回滚到旧版本的SWT.

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.

推荐答案

当前的Eclipse版本支持从导航器视图中打开Word文档(* .doc).它使用类org.eclipse.ui.internal.editorsupport.win32.OleEditor在编辑器部分中打开文档.我建议您看一下[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] 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆