用CreateOLEObject建立了一个WordApp后如何监视Word是否关闭了 用CreateOLEObject建立了一个WordApp: WordApp:= CreateOLEObject('Word.Application'); WordApp.Visible:=True;之后如何监视Word是否关闭还是继续打开? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为何不用D5自带的控件,如果嫌他不好,可以看看delphi的demo路径如下:C:\Program Files\Borland\Delphi5\Demos\Activex\Oleauto\Word8尤其是autoimpl.pas(可是原理哦) delphi自带了一个简单的word例题,但功能太简单。通过查找vba的说明,再对照delphi的vcl,编写了如下代码,实现了基本的公文管理功能。 启动word时用如下代码: begintry wordapplication.connect; except messagedlg('word may not be installed', mterror, [mbok], 0); abort; end; wordapplication.visible := true; wordapplication.caption := 'delphi automation'; end; 关闭word用如下代码。如果想保存doc文件,请修改savechanges变量的内容: var savechanges, originalformat, routedocument: olevariant; begin savechanges := wddonotsavechanges; originalformat := unassigned; routedocument := unassigned; try wordapplication.quit(savechanges, originalformat, routedocument); wordapplication.disconnect; except on e: exception do begin showmessage(e.message); wordapplication.disconnect; end; end; end; 让word打开一个指定的文件,需要先放置opendialog,然后调用wordapplication.documents.open: var itemindex :olevariant; filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert, writepassworddocument, writepasswordtemplate, format: olevariant; begin if not dlgopen.execute then exit; {open document} filename := dlgopen.filename; confirmconversions := false; readonly := false; addtorecentfiles := false; passworddocument := ''; passwordtemplate := ''; revert := true; writepassworddocument := ''; writepasswordtemplate := ''; format := wdopenformatdocument; wordapplication.documents.open( filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert, writepassworddocument, writepasswordtemplate, format ); {assign worddocument component} itemindex := 1; worddocument.connectto(wordapplication.documents.item(itemindex)); {turn spell checking of because it takes a long time if enabled and slows down winword} wordapplication.options.checkspellingasyoutype := false; wordapplication.options.checkgrammarasyoutype := false; end; 让word替换标记字符串要使用worddocument.range.find.execute,这里用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; worddocument.range.find.execute( findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike, matchallwordforms, forward, wrap, format, replacewith, replace ); end; 上面这4段代码完成了公文管理的基本功能,再把它和数据库结合起来,就可以开发一个与lotus notes类似的产品了 关于后台服务启动的次序 [讨论]写Delphi的编译器人厉害还是写VC那帮人厉害? 在Delphi中如何操作网页 高分相送:请问VCF132.OCX(控件F1Book1)为什么在打包的时候会出现注册不了的现象? 如何把数值型16进制数转换成字符型16进制数? 送分题 怎么样动态绑定事件函数 谁用过DDEServerConv和DDEClientConv控件做过DDE程序? 如何才能在memo中显示国际音标 delphi Dspack 分辨率 USB摄像头 保存 100分探讨!如何知道鼠标点击了另一个程序(比如计算器)上的第二个按钮或单选框? 求救~~!!!!!!!!
C:\Program Files\Borland\Delphi5\Demos\Activex\Oleauto\Word8
尤其是autoimpl.pas(可是原理哦)
begin
try
wordapplication.connect;
except
messagedlg('word may not be installed', mterror, [mbok], 0);
abort;
end;
wordapplication.visible := true;
wordapplication.caption := 'delphi automation';
end; 关闭word用如下代码。如果想保存doc文件,请修改savechanges变量的内容:
var
savechanges, originalformat, routedocument: olevariant;
begin
savechanges := wddonotsavechanges;
originalformat := unassigned;
routedocument := unassigned;
try
wordapplication.quit(savechanges, originalformat, routedocument);
wordapplication.disconnect;
except
on e: exception do
begin
showmessage(e.message);
wordapplication.disconnect;
end;
end;
end; 让word打开一个指定的文件,需要先放置opendialog,然后调用wordapplication.documents.open:
var
itemindex :olevariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format: olevariant;
begin
if not dlgopen.execute then
exit; {open document}
filename := dlgopen.filename;
confirmconversions := false;
readonly := false;
addtorecentfiles := false;
passworddocument := '';
passwordtemplate := '';
revert := true;
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument; wordapplication.documents.open( filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format ); {assign worddocument component}
itemindex := 1;
worddocument.connectto(wordapplication.documents.item(itemindex)); {turn spell checking of because it takes a long time if enabled and slows down winword}
wordapplication.options.checkspellingasyoutype := false;
wordapplication.options.checkgrammarasyoutype := false;
end; 让word替换标记字符串要使用worddocument.range.find.execute,这里用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; worddocument.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, forward,
wrap, format, replacewith, replace ); end; 上面这4段代码完成了公文管理的基本功能,再把它和数据库结合起来,就可以开发一个与lotus notes类似的产品了