如何使用 powershell select powerpoint 中的 table 单元格

How to select a table cell within a powerpoint using powershell

我正在尝试将特定 powerpoint 幻灯片上 table 内的单元格导出到 excel。我有一些可以运行的代码,但并不像我预期的那样。

我有:

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

它实际上创建了 excel 文件,但数据只是读取 "System.__ComObject"

如何使用 powershell 在 powerpoint 中正确引用 table 中的特定单元格?

Table.Cell 是一种 PowerPoint 方法,其中 属性:

Shape.TextFrame.TextRange.Text

保存给定单元格中文本的值。要从代码中的单元格 (1,1) 获取文本,请使用:

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