加一个WordApplication,一个WordDocument,一个opendialog
联接Word
try
Wordapplication1.Connect;
except
MessageDlg(’Word 可能没有安装!’, mtError, [mbOk], 0);
Abort;
end;
Wordapplication1.Visible := True;
打开文档
procedure TForm1.button1.Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
if not Opendiaolg1.Execute then
Exit;
FileName:=Opendiaolg1.FileName;//打开word文件
MyFileName:=FileName;
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 );
{Assign WordDocument component}
ItemIndex:= 1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplication1.Options.CheckSpellingAsYouType := False;
WordApplication1.Options.CheckGrammarAsYouType := False;
end;
[blue][/blue][^]