查了很多贴子但是没有找到解决问题的。
最近老板要我做一个程序,说起来很简单,就是开发一个word文件阅读器,这个阅读器可以打开Word文档,允许查看内容但不能编辑文档的内容。我用TOleContainer来做,代码如下:
MyWordOLE.DestroyObject;
MyWordOLE.CreateObject('Word.Document',false);
MyWordOLE.DoVerb(ovInPlaceActivate);
OLEObj:=MyWordOLE.OleObject;
//下面代码用于隐藏word的工具栏
nCmdBarCount:=OLEObj.OlePropertyGet('CommandBars').OlePropertyGet('Count');
for I := 0 to nCmdBarCount - 1 do
begin
OLEObj.OlePropertyGet('CommandBars',i+1).OlePropertySet('Enabled',false);
end;MyWordOLE是TOleContainer。
问题出在隐藏word工具栏的代码,运行程序后提示Method 'OlePropertyGet' not supported by automation object。
最近老板要我做一个程序,说起来很简单,就是开发一个word文件阅读器,这个阅读器可以打开Word文档,允许查看内容但不能编辑文档的内容。我用TOleContainer来做,代码如下:
MyWordOLE.DestroyObject;
MyWordOLE.CreateObject('Word.Document',false);
MyWordOLE.DoVerb(ovInPlaceActivate);
OLEObj:=MyWordOLE.OleObject;
//下面代码用于隐藏word的工具栏
nCmdBarCount:=OLEObj.OlePropertyGet('CommandBars').OlePropertyGet('Count');
for I := 0 to nCmdBarCount - 1 do
begin
OLEObj.OlePropertyGet('CommandBars',i+1).OlePropertySet('Enabled',false);
end;MyWordOLE是TOleContainer。
问题出在隐藏word工具栏的代码,运行程序后提示Method 'OlePropertyGet' not supported by automation object。
换用COM object试试?
for I := 0 to nCmdBarCount - 1 do
begin
OLEObj.CommandBars(i+1).Enabled := false;
end;
for I := 0 to nCmdBarCount - 1 do
begin
OLEObj.CommandBars[i+1].Enabled := false;
end;另外需要提醒一下,Office2007以后的版本中,由于采用了Ribbon风格的工具栏,所以实现的效果可能和Office2003有区别.
再次感谢,希望以后有问题能多多赐教。