Andy
Andy

Reputation: 217

How to select a table cell within a powerpoint using powershell

I am trying to export cells inside a table on a specific powerpoint slide into excel. I have some code that functions, but not as I expect.

I have:

Set-StrictMode -Version latest
$pptx  = "C:\PathToPPT.pptx"
$output   = "C:\PathToExcelSheet.csv"
$targetslide = 29

$results = @{}

Function GetPPTTable{


$objPPT = New-Object -ComObject Powerpoint.Application
$objPPT.Visible ='Msotrue'
$pp1 = $objPPT.Presentations.open($pptx)

$slide = $pp1.Slides.Item($targetslide)

$objTable = $slide.Shapes.Item(9).table.cell(1,1)

$properties = @{

      Test =$objTable

}
             $results = New-Object -TypeName PsCustomObject -Property $properties
             $results | Export-Csv $output -NoTypeInformation



    $pp1.close()
    $objPPT.quit()
}

GetPPTTable

It does in fact create the excel file, but the data simply reads "System.__ComObject"

How do I properly reference specific cells inside a table inside a powerpoint using powershell?

Upvotes: 0

Views: 430

Answers (1)

mjsqu
mjsqu

Reputation: 5417

Table.Cell is a PowerPoint Method, within which the Property:

Shape.TextFrame.TextRange.Text

Holds the value of the Text in the given cell. To get the text from cell(1,1) in your code, use:

$slide.Shapes.Item(9).table.cell(1,1).Shape.TextFrame.TextRange.Text

Upvotes: 1

Related Questions