1、打开word,用Twordapplication控件
var wenjian,Template,NewTemplate,ItemIndex:OleVariant;
程序中:
try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := '打开一个文件';
2、打开文件,用Open注意它有许多参数,含义可参考word帮助,一般我们只用第一个:
wenjian:='d:\wenjian\a1.doc';
wordapplication.Documents.Open( wenjian,false,false,
false,'','',
true,'','',
wdOpenFormatDocument);
报出:在wordapplication.Documents.Open(),报出:Types of actual and formal var parameters must be identical,
帮忙看看,那位给个写好的例子也行
var wenjian,Template,NewTemplate,ItemIndex:OleVariant;
程序中:
try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := '打开一个文件';
2、打开文件,用Open注意它有许多参数,含义可参考word帮助,一般我们只用第一个:
wenjian:='d:\wenjian\a1.doc';
wordapplication.Documents.Open( wenjian,false,false,
false,'','',
true,'','',
wdOpenFormatDocument);
报出:在wordapplication.Documents.Open(),报出:Types of actual and formal var parameters must be identical,
帮忙看看,那位给个写好的例子也行
解决方案 »
- 字段显示的问题
- 谁能详细说说 XXX.create()?
- DELPHI运行时错误,大家帮忙
- 简单的关于选定DBGrid中的记录的问题.多谢赐教!
- 投诉,投诉,我的分啊!!!
- 请教高手:delphi在连接oracle数据库时的问题
- 关于TreeView,当它有内容时,是否必须有一个是选中的?
- 我也问一个关于webbrowser的问题!!!!!!!!!!!!!
- 在database desktop中建的*.db表,现无法打开了,怎么办?
- 调查:程序员的平均寿命?
- 请问大家FastReport 怎么在程序运行后打开设计窗口,就象是双击frReport1一样
- quickreport如何编程保存为qrp文件,并从文件中读取啊?
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
http://search.csdn.net/Expert/topic/940/940196.xml?temp=.2237512