java 子窗口 swt_java辅导:使Excel嵌入到SWT窗口中

734eab8faf6e47530a9bb797366eb1f6.png

使用的Eclipse版本:3.3.1

使用的jdk版本:5.0

packagecom.jrkui.example.excel;

importorg.eclipse.swt.SWT;

importorg.eclipse.swt.layout.FillLayout;

importorg.eclipse.swt.ole.win32.OLE;

importorg.eclipse.swt.ole.win32.OleClientSite;

importorg.eclipse.swt.ole.win32.OleFrame;

importorg.eclipse.swt.widgets.Display;

importorg.eclipse.swt.widgets.Menu;

importorg.eclipse.swt.widgets.Shell;

publicclassExcelShell{

publicstaticvoidmain(String[]args){

newExcelShell().open();

}

publicvoidopen()

{

Displaydisplay=Display.getDefault();

Shellshell=newShell();

shell.setSize(600,400);

shell.setText("ExcelWindow");

shell.setLayout(newFillLayout());

//显示Excel的菜单栏

shell.setMenuBar(newMenu(shell,SWT.BAR));

createExcelPart(shell);

shell.open();

while(!shell.isDisposed()){

if(!display.readAndDispatch())

display.sleep();

}

display.close();

}

/**

*使Excel嵌入到shell中

*@paramshell

*/

privatevoidcreateExcelPart(Shellshell)

{

//OleFrame实际上是一个Composite,用于放置OLE控件

OleFrameoleFrame=newOleFrame(shell,SWT.NONE);

//OleClientSite提供一个场所用于把OLE对象嵌入到容器中,在这里“Excel.Sheet”表示的OLE对象是Excel

OleClientSiteclientSite=newOleClientSite(oleFrame,SWT.NONE,"Excel.Sheet");

//OleClientSite在显示OLE对象时所做的动作,这里的动作是OLEIVERB_SHOW,表示显示clientSite.doVerb(OLE.OLEIVERB_SHOW);

}

} 注意

嵌入Excel的方法是createExcelPart(Shell shell)

Excel.Sheet为Excel的Id,如果要嵌入Word,则其Id为Word.Document

x这是OleClientSite#doVerb()的参数的解释及可选的值:

verb – an integer value mapping to one of the following pre-defined verb values:

- Specifies the action that occurs when an end user double-clicks the object in its container. The object, not the container, determines this action. If the object supports in-place activation, the primary verb usually activates the object in place.

- Instructs an object to show itself for editing or viewing. Called to display newly inserted objects for initial editing and to show link sources. Usually an alias for some other      object-defined verb.

- Instructs an object, including one that otherwise supports in-place activation, to open itself for editing in a window separate from that of its container. If the object does not      support in-place activation, this verb has the same semantics as OLEIVERB_SHOW.

- Causes an object to remove its user interface from the view. Applies only to objects that are activated in-place.

- Activates an object in place without displaying tools, such as menus and toolbars, that end users need to change the behavior or appearance of the object.

Single-clicking such an object causes it to negotiate the display of its user-interface tools with its container. If the container refuses, the object remains active but without its tools displayed.

- Activates an object in place, along with its full set of user-interface tools, including menus, toolbars, and its name in the title bar of the container window.

- Used to tell objects to discard any undo state that they may be maintaining without deactivating the object.

如果光看解释看不明白的话,可以实际操作看看效果

2829f2ca24f0d0090cbba57f30759f23.png

java辅导:使Excel嵌入到SWT窗口中.doc

下载Word文档到电脑,方便收藏和打印[全文共1736字]

编辑推荐:

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

下载Word文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值