我不只是要打开,而是打弄程序查找替换某词后,保存,我现在也能打开只是没有保存上我修改的内容,代码如下
procedure TForm1.btn1Click(Sender: TObject);
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
end;
procedure TForm1.btn2Click(Sender: TObject);
var
SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
SaveChanges := WdSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned;
try
WordApplication.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication.Disconnect;
except
on E: Exceptiondo
begin
Showmessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;
procedure TForm1.btn3Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format, aa, bb: OleVariant;
begin
{Opendo
cument}
if not dlgOpen1.Execute then
Exit;
FileName := dlgOpen1.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument :='' ;
WritePasswordTemplate :='' ;
Format := wdOpenFormatDocument;
aa := TRUE;
bb := TRUE;
WordApplication.Visible := TRUE;
{WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, aa, bb);}
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, aa, bb);
ItemIndex := 0;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;
procedure TForm1.btn4Click(Sender: TObject);
var
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward1, Wrap, Format, ReplaceWith, Replace: OleVariant;
begin
FindText := '<#Name>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward1 := True;
Wrap := EmptyParam;
Format := False;
ReplaceWith := '123456';
Replace := True;
WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward1,
Wrap, Format, ReplaceWith, Replace,EmptyParam,EmptyParam,EmptyParam,EmptyParam );
end;