我通过创建OLE在Excel中写入数据,
eclApp:=CreateOleObject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');
... ...插入数据时正常,
但插入图片时:
WorkBook.application.Shapes.AddPicture('E:\bmp1.bmp', False,True,10,10,150,150);
报错:Method 'shapes' not supported by automation object
如何解决???谢谢!

解决方案 »

  1.   

    谢谢!
    我试过了,问题还是一样。
    编译能通过,执行插入时,报错:
    “Method 'Inlineshapes' not supported by automation object”
      

  2.   

    呵呵:)
    那你用宏录制的方法不就成了?
    这是宏代码,你加到DELPHI代码中就可以了:
        ActiveSheet.Pictures.Insert( _
            "D:\Documents and Settings\Administrator\My Documents\My Pictures\20041017164371050.jpg" _
            ).Select
      

  3.   

    试了,仍是同类型的报错。
    不知是何故?
    Method 'Pictures' not supported by automation object
      

  4.   

    var
      ExcelApp:Variant;
    begin
    ExcelApp:=CreateOleObject('Excel.Application');
    .............
    ExcelApp.ActiveSheet.Pictures.Insert('D:\Documents and Settings\Administrator\My Documents\My Pictures\20041017164371050.jpg').Select;
    .............
    end;这样啊。
      

  5.   

    下面的代码是把图片插入到指定的位置:procedure TForm1.Button2Click(Sender: TObject);
    begin
      if OpenDialog1.Execute then
        begin
          ExcelApp.ActiveSheet.Pictures.Insert(OpenDialog1.FileName).Select;
          ExcelApp.ActiveSheet.Pictures.left:=100 ;
          ExcelApp.ActiveSheet.Pictures.top:=200;
        end;
    end;已测试通过