var
Form1: TForm1;
Word:Variant;
MyDoc:Variant;
MyTable:Variant;
Range:Variant;
implementation
uses comobj;
{$R *.DFM}
//生成表格
procedure TForm1.Button1Click(Sender: TObject);
begin
Word :=CreateOleObject('word.application');
Word.visible :=True;
MyDoc :=Word.Documents.add;
Range :=Word.Selection.Range;
MyTable :=MyDoc.tables.Add(range,10,10);
end;
//向表格填值,这些对象可以在vba的对象浏览器中知道该如何引用
procedure TForm1.Button2Click(Sender: TObject);
var
i,j:Integer;
begin
for i:=1 to 10 do
for j:=1 to 10 do
MyTable.cell(i,j).Range.Text:=IntToStr(i)+IntToStr(j);
end;