通过Word模板生成Word文档

unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  ExtCtrls, ComObj, StrUtils, WordXP;
procedure TForm1.btn1Click(Sender: TObject);
var
  WordApp, WordDoc : OleVariant;
begin
  try
    WordApp := CreateOleObject('Word.Application');
  except
  end;

  WordApp.Visible := True;

  WordDoc := WordApp.Documents.Add(Template := 'D:\delphi\Word操作\chowmin.dot', NewTemplate := False);
  WordDoc.SaveAs(FileName := 'D:\delphi\Word操作\chowmin_1.doc', FileFormat := wdFormatDocument, AddToRecentFiles := False);

end;

end.

posted @ 2011-10-06 15:18  心随梦飞[fosilzhou]  阅读(280)  评论(0编辑  收藏  举报