Advertisement
Old-Lost

Export-PowerPoint

Jul 18th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Export-PowerPoint {
  2.     <#
  3.     .SYNOPSIS
  4.     Exports Charts to PowerPoint format
  5.  
  6.     .DESCRIPTION
  7.     Export the graphs to a powerpoint presentation.
  8.  
  9.     .PARAMETER  <ExportPath>
  10.     Specifies de export path (must be have either .ppt or pptx as extension).
  11.  
  12.     .PARAMETER  <Debug>
  13.     This parameter is optional, and will if called, activate the deubbing mode wich can help to troubleshoot the script if needed.
  14.  
  15.     .NOTES
  16.     -Version 0.1
  17.     -Author : Stéphane van Gulick
  18.     -Creation date: 01/06/2012
  19.     -Creation date: 01/06/2012
  20.     -Script revision history
  21.     ##0.1 : Initilisation
  22.     ##0.2 : First version
  23.     ##0.3 : Added Image possibilities
  24.  
  25.     .EXAMPLE
  26.     Exportto-html -Data (Get-Process) -Path "d:\temp\export.html" -title "Data export"
  27.  
  28.     Exports data to a HTML file located in d:\temp\export.html with a title "Data export"
  29.  
  30.     .EXAMPLE
  31.     In order to call the script in debugging mode
  32.     Exportto-html  -Image $ByteImage -Data (Get-service) "d:\temp\export.html" -title "Data Service export"
  33.  
  34.     Exports data to a HTML file located in d:\temp\export.html with a title "Data export". Adds also an image in the HTML output.
  35.     #Remark: -image must be  of Byte format.
  36.     #>
  37.     Param(
  38.  
  39.         [Parameter(mandatory = $true)]$Path = $(throw "Path is mandatory, please provide a value."),
  40.         [Parameter(mandatory = $true)]$GraphInfos,
  41.         [Parameter(mandatory = $false)]$title,
  42.         [Parameter(mandatory = $false)]$Subtitle
  43.     )
  44.  
  45.     Begin {
  46.         Add-type -AssemblyName office
  47.         Add-Type -AssemblyName microsoft.office.interop.powerpoint
  48.         #DEfining PowerPoints main variables
  49.         $MSTrue = [Microsoft.Office.Core.MsoTriState]::msoTrue
  50.         $MsFalse = [Microsoft.Office.Core.MsoTriState]::msoFalse
  51.         $slideTypeTitle = [microsoft.office.interop.powerpoint.ppSlideLayout]::ppLayoutTitle
  52.         $SlideTypeChart = [microsoft.office.interop.powerpoint.ppSlideLayout]::ppLayoutChart
  53.  
  54.         #Creating the ComObject
  55.         $Application = New-Object -ComObject powerpoint.application
  56.         #$application.visible = $MSTrue
  57.     }
  58.     Process {
  59.         #Creating the presentation
  60.         $Presentation = $Application.Presentations.add()
  61.         #Adding the first slide
  62.         $Titleslide = $Presentation.Slides.add(1, $slideTypeTitle)
  63.         $Titleslide.Shapes.Title.TextFrame.TextRange.Text = $Title
  64.         $Titleslide.shapes.item(2).TextFrame.TextRange.Text = $Subtitle
  65.         $Titleslide.BackgroundStyle = 11
  66.  
  67.         #Adding the charts
  68.         foreach ($Graphinfo in $GraphInfos) {
  69.  
  70.             #Adding slide
  71.             $slide = $Presentation.Slides.add($Presentation.Slides.count + 1, $SlideTypeChart)
  72.  
  73.             #Defining slide type:
  74.             #http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.ppslidelayout(v=office.14).aspx
  75.             $slide.Layout = $SlideTypeChart
  76.             $slide.BackgroundStyle = 11
  77.             $slide.Shapes.Title.TextFrame.TextRange.Text = $Graphinfo.title
  78.             #Adding picture (chart) to presentation:
  79.             #http://msdn.microsoft.com/en-us/library/office/bb230700(v=office.12).aspx
  80.             $Picture = $slide.Shapes.AddPicture($Graphinfo.Path, $mstrue, $msTrue, 300, 100, 350, 400)
  81.         }
  82.     }
  83.     end {
  84.         $presentation.Saveas($exportPath)
  85.         $presentation.Close()
  86.         $Application.quit()
  87.         [gc]::collect()
  88.         [gc]::WaitForPendingFinalizers()
  89.         $Application = $null
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement