调用word的文档时,出现“not enough actual parameters”错误提示,何解? ( 积分: 50 )

  • 主题发起人 主题发起人 northbin
  • 开始时间 开始时间
N

northbin

Unregistered / Unconfirmed
GUEST, unregistred user!
下述这个程序段实现调用word的存在文档,但执行后出现“not enough actual parameters”错误提示,何解?请高手指点。

var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
{Open document}
FileName := 'c:/a.txt';
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;

WordApplication1.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );

end;
 
下述这个程序段实现调用word的存在文档,但执行后出现“not enough actual parameters”错误提示,何解?请高手指点。

var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
{Open document}
FileName := 'c:/a.txt';
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;

WordApplication1.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );

end;
 
实参不足,注意word的版本,你可以到word中用宏得到参数个数。异常是由最后一行引起的。
 
uses word97 和 uses word2000 中同一个函数的参数是不一样的,估计你是把d5下的程序放到d6或者d7下了
 
有道理,我的word是2003版本,
应如何处理呢?谢谢。
 
跟你装的word没关系,关键看你用的是delphi的哪个版本,d5 uses 的是 word97,d6 uses 的是 word2000,d7 uses 的是 wordxp,它们的 WordApplication1.Documents.Open 函数的参数都不一样的,你要到相应的 .pas 文件中找具体函数的参数,然后将不需要的参数填为空即可
 
我的delphi版本为D7,已经找到wordxp.pas中的相关程序段。但不知道如何定义参数?请指点。
function Open(var FileName: OleVariant; var ConfirmConversions: OleVariant;
var ReadOnly: OleVariant; var AddToRecentFiles: OleVariant;
var PasswordDocument: OleVariant; var PasswordTemplate: OleVariant;
var Revert: OleVariant; var WritePasswordDocument: OleVariant;
var WritePasswordTemplate: OleVariant; var Format: OleVariant;
var Encoding: OleVariant; var Visible: OleVariant; var OpenAndRepair: OleVariant;
var DocumentDirection: OleVariant; var NoEncodingDialog: OleVariant): WordDocument; safecall;
 
WordApplication1.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
-----------------------------------------------------------------------
var Encoding: OleVariant; var Visible: OleVariant; var OpenAndRepair: OleVariant;
var DocumentDirection: OleVariant; var NoEncodingDialog: OleVariant):

虚线后的这些参数在你的程序中没有,可以用 emptyparam 代替
 
谢谢fenian,已经通过了。
procedure TForm1.Button1Click(Sender: TObject);
var FileName: OleVariant; var ConfirmConversions: OleVariant;
var ReadOnly: OleVariant; var AddToRecentFiles: OleVariant;
var PasswordDocument: OleVariant; var PasswordTemplate: OleVariant;
var Revert: OleVariant; var WritePasswordDocument: OleVariant;
var WritePasswordTemplate: OleVariant; var Format: OleVariant;
var Encoding: OleVariant; var Visible: OleVariant; var OpenAndRepair: OleVariant;
var DocumentDirection: OleVariant; var NoEncodingDialog: OleVariant;
begin
WordApp.Connect;
FileName:='E:/My Documents/aaa.doc';
ConfirmConversions:=false;
ReadOnly:=false;
AddToRecentfiles:=false;
PasswordDocument:='';
PasswordTemplate:='';
Revert:=false;
WritePasswordDocument:='';
WritePasswordTemplate:='';
Format:=wdFormatDocument;
//Encoding
Visible:=true;
wordapp.documents.Open(FileName,ConfirmConversions,
ReadOnly,AddToRecentFiles,
PasswordDocument,PasswordTemplate,
Revert,WritePasswordDocument,WritePasswordTemplate,Format,Encoding,Visible,OpenAndRepair,DocumentDirection,NoEncodingDialog,);
wordApp.Visible:=true;
end;
 
后退
顶部