在word2003中创建了一个模板文件(*.dot类型),下面的过程是用TWordApplicaton组件初始化Word文件,并与模板文件关联,但是有个错误提示为:Not enough actal parameters,请问该如何改正?
只是在Delphi帮助中查不到该用法,请高手赐教!
程序如下:
procedure TForm1.WordIni(Template:OleVariant);
var
    NewTemplate,ItemIndex:OleVariant;
begin
    NewTemplate:=False;
    ItemIndex:=1;
    Try
       WordApplication1.Connect;
    Except
       WordApplication1.Disconnect;
       ShowMessage('请安装Office中的Word软件!');
       exit;
    end;
    WordApplication1.Visible:=True;
    WordApplication1.Documents.Add(Template,NewTemplate);//参数不匹配错话,该如何改?
    WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
end;

解决方案 »

  1.   

    试下改成:
    WordApplication1.Documents.Add(Template, NewTemplate,EmptyParam,EmptyParam);
      

  2.   

    我的程序的意思是,建立word的文档模板(*.dot),然后在需要的用DELPHI实现替换的文本在WORD中加入批注,以下的函数WRITECOMMENTS写批注,DELETECOMMENTS删除批注,可是程序运行有一个错误,不知该如何改正?
    -----------------程序如下--------------------
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Spin, StdCtrls, ExtCtrls, Word2000, OleServer;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Label6: TLabel;
        Edit1: TEdit;
        SpinEdit1: TSpinEdit;
        SpinEdit2: TSpinEdit;
        SpinEdit3: TSpinEdit;
        SpinEdit4: TSpinEdit;
        SpinEdit5: TSpinEdit;
        SpinEdit6: TSpinEdit;
        Label7: TLabel;
        Label8: TLabel;
        Label9: TLabel;
        Label10: TLabel;
        Label11: TLabel;
        Label12: TLabel;
        RadioGroup1: TRadioGroup;
        ComboBox1: TComboBox;
        BtnPrint: TButton;
        OpenDialog1: TOpenDialog;
        WordApplication1: TWordApplication;
        WordDocument1: TWordDocument;
        procedure WordIni(Template:OleVariant);
        procedure WriteComment(explans:Array of string);
        procedure DeleteComment();
        procedure BtnPrintClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DeleteComment;
    var
        total:integer;
    begin
        total:=WordDocument1.Comments.Count;
        while total<>0 do
        begin
            WordDocument1.Comments.Item(total).Delete;
            total:=WordDocument1.Comments.Count;
        end;
    end;procedure TForm1.WordIni(Template:OleVariant);
    var
        NewTemplate,ItemIndex:OleVariant;
    begin
        NewTemplate:=False;
        ItemIndex:=1;
      //  DocumentType:=wdNewBlankDocument;
      //  Visible:=True;
        Try
           WordApplication1.Connect;
        Except
           WordApplication1.Disconnect;
           ShowMessage('请安装Office中的Word软件!');
           exit;
        end;
        WordApplication1.Visible:=True;
        WordApplication1.Documents.Add(Template,NewTemplate,EmptyParam,EmptyParam);
        WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
    end;procedure TForm1.WriteComment(explans:Array of string);
    var
        i,total:integer;
    begin
        total:=WordDocument1.Comments.Count;
        for i:=0 to total do
           WordDocument1.Comments.Item(i).Scope.Text:=explans[i-1];
    end;
    procedure TForm1.BtnPrintClick(Sender: TObject);
    var
        re: array of string;
        pathname,dotname: string;
    begin
        OpenDialog1.Options:=[ofAllowMultiSelect,ofFileMustExist];
        OpenDialog1.Filter:='Word files (*.dot)|*.dot|All files (*.*)|*.*';
        OpenDialog1.FilterIndex:=1;
        OpenDialog1.FileName:='memo.dot';
        if not OpenDialog1.Execute then
           exit;
        pathname:=ExtractFilePath(Opendialog1.FileName);
        dotname:=ExtractFileName(OpenDialog1.FileName);
        if uppercase(copy(dotname,length(dotname)-4+1,4))<>'.DOT' then
        begin
            showmessage('打开的不是Word格式文件!');
            exit;
        end;
        if uppercase(dotname)<>'MEMO.DOT' then
        begin
            showmessage('文件名不对!');
            exit;
        end;
        //初始化Word并打开模板memo.dot
        WordIni(pathname+dotname);
        setlength(re,6);
        re[0]:=Trim(Edit1.Text);
        re[1]:=RadioGroup1.Items[RadioGroup1.ItemIndex];
        re[2]:=SpinEdit1.Text+'年'+SpinEdit2.Text+'月';
        re[3]:=SpinEdit3.Text+'年'+SpinEdit4.Text+'月';
        re[4]:=SpinEdit5.Text+'年'+SpinEdit6.Text+'月';
        re[5]:=ComboBox1.Text;
        WriteComment(re);
        DeleteComment;end;end.