Using OLE in SWT to manipulate Excel (V): Set the font format for cells

Source: Internet
Author: User
Tags final ole win32

Setting the font format is a common requirement

Package com.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 Fontstyleshell {


public static void Main (string[] args) {


new Fontstyleshell (). open ();


  }


public void Open ()


  {


Display display = Display.getdefault ();


Shell shell = new Shell ();


shell.settext ("Font Style");


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 static final int cell_value_id = 0x00000006;


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


oleautomation cellA3 = Worksheet.getproperty (cell_id,new variant[]{new Variant ("A3")}). Getautomation ();


Cella3.setproperty (cell_value_id, New Variant ("Hello ole!");


Setfontstyle (cellA3);


  }


private static final int font_size = 0x00000068;


private static final int font_name = 0x0000006e;


private static final int color_index = 0x00000061;


private static final int FONT = 0x00000092;


private static final int BOLD = 0x00000060;


private static final int RED = 3;


private void Setfontstyle (oleautomation cell)


  {


oleautomation font = cell.getproperty (font). Getautomation ();//Get cell's Font object


Font.setproperty (Font_size, New Variant (32));//Size


Font.setproperty (Font_name, New Variant ("Arial Black");//use Arial Black font


Font.setproperty (Bold, New Variant (true));//Bold


Font.setproperty (Color_index, New Variant (RED));//Color


  }


}

Operation Effect:

It's simpler, and I'm not going to explain it.

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.