function Export-PowerPoint {
<#
.SYNOPSIS
Exports Charts to PowerPoint format
.DESCRIPTION
Export the graphs to a powerpoint presentation.
.PARAMETER <ExportPath>
Specifies de export path (must be have either .ppt or pptx as extension).
.PARAMETER <Debug>
This parameter is optional, and will if called, activate the deubbing mode wich can help to troubleshoot the script if needed.
.NOTES
-Version 0.1
-Author : Stéphane van Gulick
-Creation date: 01/06/2012
-Creation date: 01/06/2012
-Script revision history
##0.1 : Initilisation
##0.2 : First version
##0.3 : Added Image possibilities
.EXAMPLE
Exportto-html -Data (Get-Process) -Path “d:tempexport.html” -title “Data export”
Exports data to a HTML file located in d:tempexport.html with a title “Data export”
.EXAMPLE
In order to call the script in debugging mode
Exportto-html -Image $ByteImage -Data (Get-service) “d:tempexport.html” -title “Data Service export”
Exports data to a HTML file located in d:tempexport.html with a title “Data export”. Adds also an image in the HTML output.
#Remark: -image must be of Byte format.
#>
[fusion_builder_container hundred_percent=“yes” overflow=“visible”][fusion_builder_row][fusion_builder_column type=“1_1” background_position=“left top” background_color=“” border_size=“” border_color=“” border_style=“solid” spacing=“yes” background_image=“” background_repeat=“no-repeat” padding=“” margin_top=“0px” margin_bottom=“0px” class=“” id=“” animation_type=“” animation_speed=“0.3” animation_direction=“left” hide_on_mobile=“no” center_content=“no” min_height=“none”][cmdletbinding()]
Param(
[Parameter(mandatory=$true)]$Path = $(throw “Path is mandatory, please provide a value.”),
[Parameter(mandatory=$true)]$GraphInfos,
[Parameter(mandatory=$false)]$title,
[Parameter(mandatory=$false)]$Subtitle
)
Begin {
Add-type -AssemblyName office
Add-Type -AssemblyName microsoft.office.interop.powerpoint
#DEfining PowerPoints main variables
$MSTrue=[Microsoft.Office.Core.MsoTriState]::msoTrue
$MsFalse=[Microsoft.Office.Core.MsoTriState]::msoFalse
$slideTypeTitle = [microsoft.office.interop.powerpoint.ppSlideLayout]::ppLayoutTitle
$SlideTypeChart = [microsoft.office.interop.powerpoint.ppSlideLayout]::ppLayoutChart
#Creating the ComObject
$Application = New-Object -ComObject powerpoint.application
#$application.visible = $MSTrue
}
Process{
#Creating the presentation
$Presentation = $Application.Presentations.add()
#Adding the first slide
$Titleslide = $Presentation.Slides.add(1,$slideTypeTitle)
$Titleslide.Shapes.Title.TextFrame.TextRange.Text = $Title
$Titleslide.shapes.item(2).TextFrame.TextRange.Text = $Subtitle
$Titleslide.BackgroundStyle = 11
#Adding the charts
foreach ($Graphinfo in $GraphInfos) {
#Adding slide
$slide = $Presentation.Slides.add($Presentation.Slides.count+1,$SlideTypeChart)
#Defining slide type:
#http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.ppslidelayout(v=office.14).aspx
$slide.Layout = $SlideTypeChart
$slide.BackgroundStyle = 11
$slide.Shapes.Title.TextFrame.TextRange.Text = $Graphinfo.title
#Adding picture (chart) to presentation:
#http://msdn.microsoft.com/en-us/library/office/bb230700(v=office.12).aspx
$Picture = $slide.Shapes.AddPicture($Graphinfo.Path,$mstrue,$msTrue,300,100,350,400)
}
}
end {
$presentation.Saveas($exportPath)
$presentation.Close()
$Application.quit()
[gc]::collect()
[gc]::WaitForPendingFinalizers()
$Application = $null
}
}
Leave A Comment