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.