unit Uword;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleServer, Word97,ComObj, Buttons;type
  TForm1 = class(TForm)
    Button1: TButton;
    WordApplication: TWordApplication;
    WordDocument: TWordDocument;
    BitBtn1: TBitBtn;
    procedure Button1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
    Template,NewTemplate,ItemIndex:OleVariant;
    start,stop : olevariant ;
    myRange:range;
Begin
    Template := EmptyParam;
    NewTemplate :=  True;
    ItemIndex := 1;
    start := 3 ;
    stop := 3 ;
    try
      Wordapplication.Connect;
    except
      MessageDlg('Word may not be installed', mtError, [mbOk], 0);
      Abort;
    end;
    Wordapplication.Visible := True;
    WordApplication.Caption := 'Delphi automation';
    {Create new document}
    Template := EmptyParam;
    NewTemplate := False;
      WordApplication.Documents.Add(Template, NewTemplate);
      WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
      WordDocument.Range.InsertAfter('报表'+#13);
      WordDocument.Range.InsertAfter(#13);
    //-- 指定插入表的起始处 -------- //
      myRange := WordDocument.Range(start,stop) ;
      WordDocument.Tables.Add(myRange,11,2);
      wordDocument.Tables.Item(1).Columns.Item(1).Width :=20; //改变表格列宽
      WordDocument.Range.InsertAfter('正文一:');
end;procedure TForm1.BitBtn1Click(Sender: TObject);
var 
    Word2000: Variant; 
begin 
    try 
      Word2000:=CreateOleObject('word.basic'); 
      Word2000.FileNew; 
      Word2000.font('宋体'); //设置字体 
      Word2000.FontSize(14); //设置字号 
      Word2000.CenterPara; //居中        
      Word2000.Insert( '居中'+#13); 
      Word2000.LeftPara; //左对齐 
      Word2000.Insert( '左对齐'+#13); 
      Word2000.RightPara; //右对齐 
      Word2000.Insert( '右对齐'+#13); 
      Word2000.AppShow; //显示应用程序 
    except 
        showmessage('运行 Microsoft Word 失败!'); 
    end
end;end.