如何使用WordApplication和WordDocument组件? 高分求解!最好有代码[email protected]非常感激!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 启动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类似的产品了。 各位大哥,连接数据库问题 以前用 Dev ExpressPageControl for D6的控件现在想用D7的怎么办呢? 我新建一个群,邀请高手加盟一起研究delphi 关于数据库连接的菜鸟问题,。。 《delphi6开发人员指南》上几个概念的迷惑 ini文件使用的困惑! 请问怎样得到一个提取出月份的数据集的问题。 请问在DELPHI中的虚函数是不是也像C++中分纯虚和非纯虚??? 寻找日期时间控件 VB中的透明窗体。 ★★★ 本人申请网络编程/分布式开发小版主,欢迎提出意见 ★★★ 急,,帮我看看这个时间段的查询。。
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类似的产品了。