使Excel嵌入到SWT窗口中
来源:优易学  2011-2-9 13:18:06   【优易学:中国教育考试门户网】   资料下载   IT书店

  使用的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);
  }
  }

[1] [2] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训