Author Posts

June 19, 2016 at 4:01 pm

Dear all
How can i create powerpoint slides containing table using powershell?
i can create table in word using this code, but i need same for powerpoint

$app=New-Object -ComObject 'word.Application'
$app.Visible=$False
$doc=$app.Documents.Add()
$Range=$doc.Range()
$Number_Of_Rows=3
$Number_Of_Columns=5
$doc.Tables.Add($Range,$Number_Of_Rows,$Number_Of_Columns)|Out-Null
$Table=$doc.Tables.item(1)
$Table.Cell(1,1).Range.Text="Header 1"
$Table.Cell(1,2).Range.Text="Header 2"
$Table.Cell(1,3).Range.Text="Header 3"
$Table.Cell(2,1).Range.Text="Row content 1"
$Table.Cell(2,2).Range.Text="Row content 2"
$Table.Cell(2,3).Range.Text="Row content 3"

$Table.AutoFormat(9)

$file='C:\tempFiles\doc1.docx'
$doc.SaveAs([ref]$file)
$doc.close()
$app.quit()
[System.Runtime.interopservices.Marshal]::ReleaseComObject($doc)|Out-Null
[System.Runtime.interopservices.Marshal]::ReleaseComObject($app)|Out-Null
[System.Runtime.interopservices.Marshal]::ReleaseComObject($Range)|Out-Null
[System.Runtime.interopservices.Marshal]::ReleaseComObject($Table)|Out-Null

Remove-Variable doc,app,Range,Table
[gc]::collect()
[gc]::WaitForPendingFinalizers()

Regards
Mohammed Sharkawy

June 22, 2016 at 8:45 am

Hello
i found the required code for this :

Add-type -AssemblyName office
Add-Type -AssemblyName microsoft.office.interop.powerpoint
[object] $powerPoint = New-Object -ComObject PowerPoint.Application
$powerPoint.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
[object] $presentation = $powerPoint.Presentations.Add($true)

$presentation.ApplyTheme("C:\tempFiles\Theme1.thmx")
    $Number_Of_Rows=2
    $Number_Of_Columns=8
	[object] $Table = $Slide.Shapes.AddTable($Number_Of_Rows,$Number_Of_Columns,0,30)
	
	$Table.Table.Columns.Item(1).Width = 100
   $Table.Table.Columns.Item(2).Width = 90
   $Table.Table.Columns.Item(3).Width = 90
   $Table.Table.Columns.Item(4).Width = 80
   $Table.Table.Columns.Item(5).Width = 80
   $Table.Table.Columns.Item(6).Width = 90
   $Table.Table.Columns.Item(7).Width = 100
   $Table.Table.Columns.Item(8).Width = 90
   
   $Table.table.Cell(1,1).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,2).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,3).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,4).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,5).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,6).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,7).Shape.TextFrame.TextRange.Font.size=14
   $Table.table.Cell(1,8).Shape.TextFrame.TextRange.Font.size=14
   
   $Table.table.Cell(2,1).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,2).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,3).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,4).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,5).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,6).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,7).Shape.TextFrame.TextRange.Font.size=12
   $Table.table.Cell(2,8).Shape.TextFrame.TextRange.Font.size=12
   
   #$Table.table.Cell(1,1).Shape.TextFrame.TextRange.Font.Bold = 'msoTrue'
   $Table.table.Cell(1,1).shape.TextFrame.TextRange.Text="CRQ"
   $Table.table.Cell(1,2).Shape.TextFrame.TextRange.Text="Change-Deployment Summary"
   $Table.table.Cell(1,3).Shape.TextFrame.TextRange.Text="Change Description"
   $Table.table.Cell(1,4).Shape.TextFrame.TextRange.Text="Benefits"
   $Table.table.Cell(1,5).Shape.TextFrame.TextRange.Text="Business Impact"
   $Table.table.Cell(1,6).Shape.TextFrame.TextRange.Text="Risk"
   $Table.table.Cell(1,7).Shape.TextFrame.TextRange.Text="Business/Service Owner Approvals"
   $Table.table.Cell(1,8).Shape.TextFrame.TextRange.Text="Hypercare Approval"
   
   $file='C:\tempFiles\ccc3.pptx'
   $presentation.SaveAs($file)