打开word:<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>try<br>Wordapplication1.Connect;<br>except<br>MessageDlg('Word may not be installed', mtError, [mbOk], 0);<br>Abort;<br>end;<br>Wordapplication1.Visible := True;<br>WordApplication1.Caption := 'Delphi automation';<br>end;<br>打开文件<br>procedure TForm1.Button3Click(Sender: TObject);<br>var <br>ItemIndex :OleVariant; <br>FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, <br>PasswordDocument, PasswordTemplate, Revert, <br>WritePasswordDocument, WritePasswordTemplate, Format: OleVariant; <br>begin<br>{Open document} <br>FileName := 'c:/a.txt'; <br>ConfirmConversions := False; <br>ReadOnly := False; <br>AddToRecentFiles := False; <br>PasswordDocument := '';<br>PasswordTemplate := ''; <br>Revert := True; <br>WritePasswordDocument := '';<br>WritePasswordTemplate := '';<br>Format := wdOpenFormatDocument; <br><br>WordApplication1.Documents.Open( FileName, ConfirmConversions,<br>ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, <br>Revert, WritePasswordDocument, WritePasswordTemplate, Format ); <br><br>{Assign WordDocument component} <br>ItemIndex := 1;<br>WordDocument.ConnectTo(WordApplication1.Documents.Item(ItemIndex));<br><br>{Turn Spell checking of because it takes a long time if enabled and slows down Winword} <br>WordApplication1.Options.CheckSpellingAsYouType := False;<br>WordApplication1.Options.CheckGrammarAsYouType := False; <br>end;<br>