打开WORD时...(30分)

  • 主题发起人 主题发起人 iseek
  • 开始时间 开始时间
I

iseek

Unregistered / Unconfirmed
GUEST, unregistred user!
在程序中调用WORD不难,但我想在调用WORD时,让WORD打开一个文件,注意,不是.doc文<br>档,而是一个文本文件。<br>这可能吗?<br>
 
Easylee,嫌分不够?<br>你说要多少?<br>
 
打开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>
 
var a:OleVariant;<br>begin<br>&nbsp; WordApplication1.Connect;<br>&nbsp; WordApplication1.Visible:=True;<br>&nbsp; a:='c:/a.txt';<br>&nbsp; WordApplication1.Documents.Open(a,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);<br>
 
Documents.Open FileName:="abcd.txt", ConfirmConversions:=False, ReadOnly _<br>&nbsp; &nbsp; &nbsp; &nbsp; :=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _<br>&nbsp; &nbsp; &nbsp; &nbsp; :="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _<br>&nbsp; &nbsp; &nbsp; &nbsp; , Format:=wdOpenFormatAuto<br><br>将上面的宏转化为DElphi即可
 
如果你只想这样:<br>WinExec('C:/Program Files/Microsoft Office 2000/Office/WINWORD.exe d:/a.txt',SW_SHOW);
 
哈哈,很精彩。<br>我出的分太少,分配如下:<br>ccgaosong10分<br>menxin10分<br>wk_knife10分<br>谢谢<br>
 
后退
顶部