3

我正在用 Dephi XE3 编写一个 PowerPoint 插件,它会插入一个表格并用一些文本填充它。我几乎完成了它,但我无法用文本填充表格。

这是我的代码:

insp:=CreateOleObject('PowerPoint.Application');
insp.ActivePresentation.Slides.Add(1, ppLayoutBlank);
MSTable:=insp.ActivePresentation.Slides.Item(1);
MSTable.Shapes.AddTable(5, 5, 100, 0);
MSTable.Table.Cell(2,2).Shape.TextFrame.TextRange.Text:='Text';

当我尝试填写表格时,出现此错误

自动化对象不支持方法“表”

也试过这个:

MSTable.AddTable(5, 5, 100, 0).Cell(2,2).Shape.TextFrame.TextRange.Text:='Text';
MSTable.Table.Item(1).Cell(2,2).Shape.TextFrame.TextRange.Text:='Text';

在 MSDN 上找到了如何在 VBA 中编写此代码,但没有帮助。请帮我解决这个问题。

4

1 回答 1

3

遵循这个MSDN 示例,这就是您应该创建和访问PowerPoint-table的方式

var
  LApp, LSlide, LTable : Variant;
begin
  LApp := CreateOleObject( 'PowerPoint.Application' );
  LSlide := LApp.ActivePresentation.Slides.Add( 1, ppLayoutBlank );
  LTable := LSlide.Shapes.AddTable( 5, 5, 100, 0 ).Table;

  LTable.Cell( 2, 2 ).Shape.TextFrame.TextRange.Text := 'Text';
于 2013-08-05T08:22:28.917 回答