Here is a example:
1. create a new app
2. put a F1Book on Form1
3. Add a button1 captioned 'Format Cells'
4. Add a PopupMenu with a menuitem called 'PopupMenuItem1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AxCtrls, OleCtrls, vcf1, Menus;
type
TForm1 = class(TForm)
F1Book1: TF1Book;
Button1: TButton;
PopupMenu1: TPopupMenu;
PopupMenuItem1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure F1Book1RClick(Sender: TObject;
nRow, nCol: Integer);
procedure PopupMenuItem1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Row, Col: integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//Format the Selected range
procedure TForm1.Button1Click(Sender: TObject);
var
pLeft, pRight, pTop, pBottom: SmallInt;
{ 0 No Border
1 Thin Line
2 Medium Line
3 Dashed Line
4 Dotted Line
5 Thick Line
6 Double Line
7 Hairline}
pShade: SmallInt;
pcrLeft, pcrRight,
pcrTop, pcrBottom: TCOLOR;
begin
with F1Book1do
begin
EntryRC[1,2] := '这是一个表格测试';
SetSelection(2,2,4,6);
GetBorder(pLeft, pRight, pTop, pBottom, pShade, pcrLeft, pcrRight, pcrTop, pcrBottom);
SetBorder( 2, 1,1,1,1, pShade, clRed, pcrLeft, pcrRight, pcrTop, pcrBottom);
EntryRC[2,2] := '1';
EntryRC[2,3] := '2';
FormulaRC[2,4] := 'B2+C2';
end;
end;
//Show PopupMenu on a cell
procedure TForm1.F1Book1RClick(Sender: TObject;
nRow, nCol: Integer);
var p: TPoint;
begin
Row := nRow;
Col := nCol;
GetCursorPos(p);
PopupMenu1.Popup( P.X, P.y );
end;
//After click the PopupMenu, get your data from any where
//and assign the value to the cell
procedure TForm1.PupupMenuItem1Click(Sender: TObject);
begin
F1Book1.EntryRC[Row, Col] := 'Data can be calculated from a database, and put it here!';
end;
end.