如何從Delphi中修改現有 excel形狀的文本?從Delphi修改Excel形狀
我可以創建一個新形狀並設置其文本
procedure TForm1.Button1Click(Sender: TObject);
var
excel, xlShape : variant;
begin
olecontainer1.CreateObject('Excel.Application',false);
excel := olecontainer1.OleObject;
excel.workbooks.open('C:\test.xls');
XlShape := excel.application.worksheets[1].Shapes.AddShape(1, 0, 0, 450, 200);
XlShape.textframe.characters.text:='new shape created from Delphi';
但是,如果形狀已經存在,我怎麼能選擇它來改變其text屬性?喜歡的東西:
excel.application.worksheets[1].Shapes('shape1').textframe.characters.text := 'This gives error';
通常情況下,最簡單的方法找出如何做事OLE自動化是在Excel中記錄宏,然後查看它生成的代碼。將其轉換爲Delphi語法非常簡單。 – 2009-08-05 03:43:04