Search code examples
vbadelphipowerpoint

PowerPoint in Delphi: fill table with text


I'm writing an add-in to PowerPoint in Dephi XE3, which would insert a table and fill it with some text. I am almost done with it, but I can't fill a table with text.

This is my code:

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';

When I'm trying to fill a table, I'm getting this error

Method 'Table' not supported by automation object

Also tried this:

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';

On MSDN found how to write this code in VBA, but doesn't help. Please help me solve this problem.


Solution

  • Followed this MSDN example thats the way you should create and access the 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';