在SWT中使用OLE操作Excel(一):使Excel嵌入到SWT窗口中 - 编程入门网
在SWT中使用OLE操作Excel(一):使Excel嵌入到SWT窗口中时间:2011-07-06使用的Eclipse版本:3.3.1 使用的jdk版本:5.0 packagecom.jrkui.example.excel; import org.eclipse.swt.SWT;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.ole.win32.OLE;import org.eclipse.swt.ole.win32.OleClientSite;import org.eclipse.swt.ole.win32.OleFrame;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.Shell;public class ExcelShell { public static void main(String[] args) { new ExcelShell().open(); } public void open() { Display display = Display.getDefault(); Shell shell = new Shell(); shell.setSize(600,400); shell.setText("Excel Window"); shell.setLayout(new FillLayout()); //显示Excel的菜单栏 shell.setMenuBar(new Menu(shell,SWT.BAR)); createExcelPart(shell); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } display.close(); } /** * 使Excel嵌入到shell中 * @param shell */ private void createExcelPart(Shell shell) { //OleFrame实际上是一个Composite,用于放置OLE控件 OleFrame oleFrame = new OleFrame(shell,SWT.NONE); //OleClientSite提供一个场所用于把OLE对象嵌入到容器中,在这里“Excel.Sheet”表示的OLE对象是Excel OleClientSite clientSite = new OleClientSite(oleFrame,SWT.NONE,"Excel.Sheet"); //OleClientSite在显示OLE对象时所做的动作,这里的动作是OLEIVERB_SHOW,表示显示 clientSite.doVerb(OLE.OLEIVERB_SHOW); }} 在SWT中使用OLE操作Excel(一):使Excel嵌入到SWT窗口中(2)时间:2011-07-06显示结果: 注意 嵌入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 o |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |