Delphi与c++builder操作Ole的区别

使用TOleContainer加载个word文档,隐藏缺省的会显示菜单栏和工具栏

1、c++builder方法

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    OleContainer1->DestroyObject();

    OleContainer1->CreateObject("Word.Document", false);
    OleContainer1->DoVerb(ovInPlaceActivate);

    Variant vObj = OleContainer1->OleObject;
    int nCmdBarCount = vObj.OlePropertyGet("CommandBars").OlePropertyGet("Count");

    for (int i =0; i < nCmdBarCount; i++)
    {
        vObj.OlePropertyGet("CommandBars", i + 1).OlePropertySet("Enabled", false);
    }
}

2、Delphi方法

    nCmdBarCount := OLEObj.CommandBars.Count;
    for I := 0 to nCmdBarCount - 1 do
    begin
      OLEObj.CommandBars[i+1].Enabled := false;
    end;

即OlePropertyGet和OlePropertySet是c++builder专用的,Delphi中不能用。

但是TOleContainer针对Office2007总会有这样那样的问题,有点不尽人意,特别是在编辑Office文档时,如果只是显示使用TOleContainer还是可以的。

procedure TFm_Main.Button2Click(Sender: TObject);
var
  vObj:Variant;
  nCmdBarCount,i:integer;
  filePath:string;
begin
  try
    filePath := AppPath + '揭示板.xls';
    OleContainer1.DestroyObject();
    OleContainer1.CreateObjectFromFile(filePath,false);
    OleContainer1.DoVerb(ovInPlaceActivate);

    vObj := OleContainer1.OleObject;
    nCmdBarCount := vObj.CommandBars.Count;
    for i := 0 to nCmdBarCount - 1 do
      vObj.CommandBars[i+1].Enabled := false;
  except
    ShowMessage(Exception(ExceptObject()).Message);
  end;
end;


procedure TFm_Main.Button1Click(Sender: TObject);
var
  EApp:Variant;
  filePath:string;
begin
  EApp:=CreateOleObject('Excel.Application');
  filePath := AppPath + '揭示板.xls';
  Windows.SetParent(EApp.HWND,Panel19.Handle);
  EApp.Workbooks.Open(filePath);
  EApp.Visible:=true;
end;


参考:http://bbs.csdn.net/topics/320005950

http://bbs.csdn.net/topics/320118166

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值