java的swt文档,使用Java中的Eclipse SWT OleClientSite打开扩展名为.doc的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));

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.

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值