启动Word有两种方式,好像用Delphi的Server控件組比较安全些。
不用控件:
procedure TForm1.Button1Click(Sender: TObject);
var
V: OLEVariant;
vApp:Variant;
begin
procedure TForm1.Button1Click(Sender: TObject);
var
vDoc,vTab:variant;
StrTemplate:String;
i,j:Integer;
begin
try
try
Table1.First;
StrTemplate:=StrStarDir+'/Delphi报表.dot';
StrOutDoc:=StrStarDir+'/Delphi_Report.Doc';
if varType(vApp)=varEmpty then
vApp:=createoleobject('Word.Application');
vDoc:=vApp.Documents.Add(Template:=StrTemplate,NewTemplate:=False);end;
except
vApp.Quit;
vApp:=UnAssigned;
ShowMessage('Some Thing Wrong When Run Microsoft Word!');
end;
用TWordApplication控件:
var
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format: OleVariant;
begin
WordApplication1.Connect;
WordApplication1.Visible := True;
FileName := 'c:/windows/script.doc';
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := True;
PasswordDocument := EmptyParam;
PasswordTemplate := EmptyParam;
Revert := False;
WritePasswordDocument := EmptyParam;
WritePasswordTemplate := EmptyParam;
Format := EmptyParam;
WordApplication1.Documents.Open(FileName, ConfirmConversions, ReadOnly,
AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format);
end;