2016-04-21 33 views
1

我想将Powerpoint Presantation中的幻灯片复制到另一个PowerShell中。 任何人都可以帮助我吗?使用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 

回答

0

尝试使用此方法:

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

语法: 文件名:=“C:\ p1.pptx”指数:= 54(在新的PPT),SlideStart:= 54,SlideEnd:= 54

无需复制和粘贴

+0

如果要更换,而不是的添加,你可以像这样删除幻灯片: $ pp2.Slides.Item(x).Delete() –

+0

它工作正常! 非常感谢! –

+0

欢迎您。你能接受作为答案! –

相关问题