2013-08-05 28 views
3

我正在爲Dephi XE3中的PowerPoint寫一個加載項,它會插入一個表格並填充一些文本。我幾乎完成了它,但我無法用文字填充表格。Delphi中的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中編寫此代碼,但沒有幫助。請幫我解決這個問題。

+2

如果「addtable」是一種方法,請把「錯誤」來「這個錯誤」,其次是真正的錯誤消息 –

+0

'MSTable.Shapes',那麼你可能需要編寫MSTable.Shapes.Table.item(1).cell(2,2)......:='text'; –

+0

@諾曼紐曼,不幸的是同樣的錯誤。 – Rinat

回答

3

遵循了這一MSDN example這是你應該創建和訪問的方式PowerPoint - 表

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

它的工作原理!非常感謝你! – Rinat

+1

正如你所看到的,我只是遵循了VBA的例子; o) –