使用Powershell将幻灯片从一个Powerpoint Presantation复制到另一个

时间:2016-04-21 10:50:36

标签: powershell powerpoint

我想通过Powershell将幻灯片从一个Powerpoint Presantation复制到另一个幻灯片。 有谁可以帮助我?

这是我的代码不起作用:

Add-type -AssemblyName office

$npath = “C:\p3.pptx"
$test = Test-Path $npath 
if($test = $true){Remove-Item $npath }

$ppo = New-Object -ComObject powerpoint.application 

$p1 = “C:\p1.pptx"
$p2 = “C:\p2.pptx"

$pp1 = $ppo.Presentations.open($p1)
$pp2 = $ppo.Presentations.open($p2)

$pp2.Slides.item(54).copy()
$pp1.Slides.item(54).paste()

#I have tried it too, but it doesn't work:
# $cs = $pp2.Slides.item(54)
# $pp1.Slides.item(54).copy($cs)

$pp1.Saveas($npath)
$pp1.Close()
$pp2.Close()

$ppo.quit()
$ppo = $null

1 个答案:

答案 0 :(得分:0)

尝试使用此方法:

$pp2.Slides.InsertFromFile($p1,54,54,54)

语法: FileName:=“C:\ p1.pptx”,索引:= 54(在新的ppt中),SlideStart:= 54,SlideEnd:= 54

无需复制和粘贴。