让Word打开一个指定的文件需要先放置OpenDialog然后调用WordApplicationDocumentsOpen
var
ItemIndex :OleVariant;
FileName ConfirmConversions ReadOnly AddToRecentFiles
PasswordDocument PasswordTemplate Revert
WritePasswordDocument WritePasswordTemplate Format: OleVariant;
begin
if not dlgOpenExecute then
Exit;
{Open document}
FileName := dlgOpenFileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := ;
PasswordTemplate := ;
Revert := True;
WritePasswordDocument := ;
WritePasswordTemplate := ;
Format := wdOpenFormatDocument;
WordApplicationDocumentsOpen( FileName ConfirmConversions
ReadOnly AddToRecentFiles PasswordDocument PasswordTemplate
Revert WritePasswordDocument WritePasswordTemplate Format );
{Assign WordDocument component}
ItemIndex := ;
WordDocumentConnectTo(WordApplicationDocumentsItem(ItemIndex));
{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplicationOptionsCheckSpellingAsYouType := False;
WordApplicationOptionsCheckGrammarAsYouType := False;
end;
让Word替换标记字符串要使用WordDocumentRangeFindExecute这里用Delphi替换了<#Name>
var
FindText MatchCase MatchWholeWord MatchWildcards MatchSoundsLike MatchAllWordForms Forward Wrap Format ReplaceWith Replace: OleVariant;
begin
FindText := <#Name>;
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward := True;
Wrap := wdFindContinue;
Format := False;
ReplaceWith := Delphi;
Replace := True;
WordDocumentRangeFindExecute( FindText MatchCase MatchWholeWord MatchWildcards MatchSoundsLike MatchAllWordForms Forward Wrap Format ReplaceWith Replace );
end;
上面这段代码完成了公文管理的基本功能再把它和数据库结合起来就可以开发一个与Lotus Notes类似的产品了
[] []