我给你一个小例子:
procedure TfrmPlag.BtnPrintClick(Sender: TObject);
Var
Y1,M1,D1:Word;
i,j:integer;
Vdate:OleVariant;
begin
try
WordAplag.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
WordAplag.Documents.AddOld(EmptyParam,EmptyParam);
DecodeDate(Now,Y1,M1,D1);
//******************* 写脚文件 *************************
WordAplag.Selection.TypeParagraph;
WordAplag.Selection.Font.Bold :=0;
WordAplag.Selection.Font.Size :=10;
WordAplag.Selection.ParagraphFormat.Alignment := wdAlignParagraphright;
Vdate :='打印人员:'+Auserinfo.UserName +
' 打印日期:'+formatdatetime('yyyy"年"mm"月"dd"日"',now);
WordAplag.ActiveDocument.sentences.Last.Text :=Vdate;
//******************* 写头文件 *************************
WordAplag.Selection.Font.Name :='宋体';
WordAplag.Selection.Font.Bold :=1;
WordAplag.Selection.Font.Size := 14;
WordAplag.Selection.ParagraphFormat.Alignment :=wdAlignParagraphCenter;
WordAplag.Selection.TypeText(inttostr(Y1)+'年'+inttostr(M1)+'月固定资产折旧表');
//*******************写正文部分 *************************
WordAplag.Selection.TypeParagraph;
WordAplag.Selection.Font.Size :=9;
WordAplag.Selection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
WordAplag.Selection.Tables.AddOld(WordAplag.Selection.Get_Range ,Sgrdshow.Rowcount,10);
WordAplag.Selection.Cells.Width:=100;
for i:=1 to Sgrdshow.Colcount-1 do begin
for j:=0 to Sgrdshow.Rowcount-1 do begin
WordAplag.ActiveDocument.tables.Item(1).Cell(j+1,i).Range.Text :=Sgrdshow.Cells[i,j];
End ;
End;
WordAplag.Visible :=True;
WordAplag.Disconnect ;
end;