Using OLE in SWT to manipulate Excel (c)--set cell background color

Source: Internet
Author: User
Tags ole win32

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));


}


}

Related Article

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.