好好看看Delphi自带的一个例子!!!
解决方案 »
- delphi提交表单
- delphi7做报表时遇到的一个奇怪的现象
- 查询没有出现过的内容
- 招聘了,招聘了,不信DELPHI的人这么难招,顶者有分,不够再开
- ini建树,高手进来。高分相送。
- ado如何访问ACCESS数据库!?
- 马上结贴的问题
- 问问大家:那一种报表控件比较好?欢迎讨论
- delphi6的多文档结构中,打开一个子窗口后,主窗体的caption会改变,如何使它不变?
- 假如我用了一个TImage控件再窗体中显示以图片,那么这个图片会放在那些文件里?(*.dcu,*.pas,*,dfm,*.res...)
- 除了Image Editor,还有什么工具可以编辑res类型的资源文件?--急用!!!
- 大家进来看看我使用ADO遇到的问题
启动word时用如下代码:
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;
在单元中 uses ComObj;unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Dialogs, StdCtrls,ComObj;
//*******//
在按钮中:
procedure TForm1.Button1Click(Sender: TObject);
var a :variant;
begin
try
a:=createoleobject('word.basic');
a.appshow;
a.filenew;
a.insert('open word succeed!');
except
showmessage('确定word是否安装!');
end;
end;