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.OleAutomation;
import Org.eclipse.swt.ole.win32.OleClientSite;
import Org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import Org.eclipse.swt.widgets.Display;
import Org.eclipse.swt.widgets.Shell;
public class Colorrangeshell {
public static void Main (string[] args) {
new Colorrangeshell (). open ();
}
public void Open ()
{
Display display = Display.getdefault ();
Shell shell = new Shell ();
shell.settext ("Color Range shell");
shell.setsize (400, 300);
Shell.setlayout (New Filllayout ());
Createexcelpart (shell);
Shell.open ();
while (!shell.isdisposed ())
if (!display.readanddispatch ())
Display.sleep ();
Display.dispose ();
}
private static final int sheet_id = 0x000001e5;
private static final int cell_id = 0X000000C5;
private void Createexcelpart (shell shell)
{
oleframe frame = new Oleframe (SHELL,SWT. NONE);
oleclientsite clientsite = new Oleclientsite (FRAME,SWT. NONE, "Excel.Sheet");
Clientsite.doverb (OLE. Oleiverb_show);
oleautomation workbook = new Oleautomation (clientsite);
oleautomation worksheet = Workbook.getproperty (sheet_id, New variant[]{new Variant (1)}). Getautomation ();
//Get cell
oleautomation cellA1 = Worksheet.getproperty (cell_id, New variant[]{new Variant ("A1")}). Getautomation ();
oleautomation cellD1 = Worksheet.getproperty (cell_id, New variant[]{new Variant ("D1")}). Getautomation ();
//Get cell range
oleautomation areaa3d5 = Worksheet.getproperty (cell_id,new variant[]{new variant ("A3"), new variant ("D5")}). GE Tautomation ();
colorrangebyred (cellA1);
colorrangebyred (cellD1);
colorrangebyred (AREAA3D5);
}
/**
* The ID of the method to obtain interior in range
*/
private static final int INTERIOR = 0x00000081;
/**
* The ID of the method to assign a value to ColorIndex in interior
*/
private static final int color_index = 0x00000061;
/**
* Red in Excel's index is 3
*/
private static final int RED = 3;
/**
* Use red as the background color for range
* @param automation
*/
private void colorrangebyred (oleautomation automation)
{
//Get interior
oleautomation interior = automation.getproperty (interior). Getautomation ();
//Set color
Interior.setproperty (Color_index, New Variant (RED));
}
}