我要在程序中调用word,首先要派断本地机是否装了OFFICE,还有获得它的全路径,请教各位怎么做
解决方案 »
- 如何将图片转换成字符串,并保存到oracle9i blob字段中,并能正确读出?????
- 用ExcelApp.cells[3,3].value,取单元格的值时不是我想要的时间,这个怎么办
- 请问当鼠标移动到ListView的某个项目上时(未点击)会触发什么事件吗?
- 求一SQL语句
- 您认为幼稚的问题!还请帮助
- 为什么我把窗体1 的名字设为LOGIN,而保存窗体1时文件名就不能为LOGIN呢??
- 怎么导入窗体?
- 请教memo+sql+treeview的问题
- 朱小军请进!
- 兩個query如何關聯
- 怎样在copyfile文件中显示拷贝进度
- 奇怪!为什么啊,请帮忙看看!100分送上(关于托盘,让窗体显示在最上方)
后期绑订,使用IDispatch接口,代码编译时并不了解你所需要操作的对象是什
么,程序运行过程中(Runtime)才实现和OLE服务器的真正连接,所有变量使用Variant
类型,代码性能应该较差(仅仅猜测)。但是这种方式代码较为简单易懂,易于自己编写
复杂的控制。以下是一个同样打开Access程序的代码。 var
Access: Variant;
begin
try
Access := GetActiveOleObject('Access.Application');
except
Access := CreateOleObject('Access.Application');
end;
Access.Visible := True;
...
end;
ExtractFilePath('winword.exe');//获得Word的可执行文件的全路径
读Path的值
启动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;
2、CreateComObject('Word.appliction')
ExcelApp := CreateOleObject('Word.application');
except on raise '未装word';
MSExcel := CreateOleObject('Word.Basic');
except
ShowMessage('Could not start Microsoft Word.');
Exit;
end;
try
except
try
except
ShowMessage('Microsoft Word version is not German, French or English.');
Exit;
end;
end;
v: variant;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
try
wordapplication.connect;
v := CreateOleObject('Excel.Application');
v.visible := True;
except
messagedlg('word not installed', mterror, [mbok], 0);
abort;
end; end;
改为 v := CreateOleObject('word.Application');
begin
mystring:='.doc';
FReg:=TRegistry.Create ; //创建TRegistry对象
FReg.RootKey :=HKEY_CLASSES_ROOT;
if FReg.OpenKey(mystring,False) then
begin
mystring:=FReg.ReadString('');
FReg.CloseKey ;
Mystring:=mystring+'\'+'shell'+'\'+'open'+'\'+'command'
FReg.OpenKey(mystring,False);
mystring:=FReg.ReadString('');
showmessage(trim(mystring));//显示相应的应用程序完整信息
end
end;
begin
try
wordfile:=createoleobject('word.basic');
except
showmessage('could not find word');
exit;
if (lang='English (US)')or (lang='English (UK)') then
begin
msword.appshow;
msword.fileopen('22.doc');
mswrod.filesaveas(format:=6,name:='dfdfd.htm'); //转存为htm格式