PoshCode Archive  Artifact [4c6a8aaa05]

Artifact 4c6a8aaa05f17b31a52ae435bac43de0fa705732113cb2df2e26cffb7374ab90:

  • File Out-Pptx.ps1 — part of check-in [9433b3cb08] at 2018-06-10 13:44:25 on branch trunk — Output text to a new PowerPoint slide (user: Joel Bennett size: 1548)

# encoding: ascii
# api: powershell
# title: Out-Pptx
# description: Output text to a new PowerPoint slide
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Out-Pptx
# x-poshcode-id: 4673
# x-archived: 2017-02-09T13:52:35
# x-published: 2014-12-09T06:10:00
#
#
Add-Type -AssemblyName Office
Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint

function Out-Pptx {
   [CmdletBinding()]
   param(
      [Parameter(ValueFromPipeline=$true)]
      $Content,

      $Presentation = "~\SkyDrive\Presentations\Intro to PowerShell.pptx"
   )
   begin {
      try {
         $PowerPoint = [System.Runtime.InteropServices.Marshal]::GetActiveObject('PowerPoint.Application')
      } catch {
         $PowerPoint = New-Object -ComObject PowerPoint.Application
         $PowerPoint.visible = [Microsoft.Office.Core.MsoTriState]::MsoTrue
         $Presentation = $PowerPoint.Presentations.Open( $Presentation )
      }

      if(!$Presentation) {
         $Last = $PowerPoint.Presentations.Count
         $Presentation = $PowerPoint.Presentations.Item($Last)
      }
   }

   process {
      $Count = $Presentation.Slides.Count
      $Slide = $Presentation.Slides.AddSlide($Count+1, $Presentation.Slides.Item($Count).CustomLayout)
      # $Slide.Layout = [Microsoft.Office.Interop.PowerPoint.PpSlideLayout]::ppLayoutText

      $slide.Shapes.Title.TextFrame.TextRange.Text = "PS> " + $MyInvocation.Line
      $Slide.Shapes.Item(2).TextFrame.TextRange.Text = $Content
   }
}