Using OLE in SWT to manipulate Excel (a): Embed Excel in the SWT window

Source: Internet
Author: User
Tags ole win32

Eclipse version in use: 3.3.1

JDK version used: 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 ());
//Show Excel's Menu bar
Shell.setmenubar (New menu, SHELL,SWT. BAR));
Createexcelpart (shell);
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ())
Display.sleep (); br>}
DisplaY.close ();
}
/**
* Make excel embedded in the shell
* @param Shell
*/
private void Createexcelpart (shell Shell)
{
//oleframe is actually a composite that is used to place the OLE control
Oleframe oleframe = new Oleframe (SHELL,SWT. NONE); The
//oleclientsite provides a place for embedding OLE objects into containers where the OLE object represented by "Excel.Sheet" is Excel
oleclientsite clientsite = new O Leclientsite (OLEFRAME,SWT. NONE, "Excel.Sheet");
//oleclientsite The action that is done when the OLE object is displayed, where the action is oleiverb_show, representing the display
Clientsite.doverb OLE. Oleiverb_show);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.