如何使用powershell创建powerpoint表

时间:2013-10-24 18:58:16

标签: powershell powerpoint

我目前正在尝试使用powershell在powerpoint中创建日历。我想做的就是将表格插入powerpoint幻灯片。此表格代表1月份,它包含星期几等。

我做了一些研究并遇到了this

这是VB脚本,所以我试图在powershell中“创建它的等价物”:

EDIT3:我终于可以从Excel复制我的表格并使用以下代码将其粘贴到我的powerpoint幻灯片中:

#Create an instance of Excel.
$xl=New-Object -ComObject "Excel.Application"
$xl.Visible = $True

#Open the Excel file containing the table. 
$wb = $xl.workbooks.open("C:\January.xls")
$ws = $wb.ActiveSheet

#Select the table.
$range = $ws.range("A1:G7")
$range.select()

#Copy the table to the clipboard.
$range.copyPicture()

#Create an instance of Powerpoint.
$objPPT = New-Object -ComObject "Powerpoint.Application"
$objPPT.Visible ='Msotrue'

#Add a slide to the presentation.    
$project = $objPPT.Presentations.Add()
$slide  = $project.Slides.Add(1, 1)

#Paste the table into the slide.
$shape = $slide.Shapes.Paste()

#Position the table.
$shape.Left = 50
$shape.Top = 150
$shape.Width = 300
$shape.Height = 168

感谢那些在这里和#powershell帮助过我的人

2 个答案:

答案 0 :(得分:0)

我认为你可以使用它:

# Optionally, make sure you're on the last slide:
$ppt.ActiveWindow.View.GotoSlide( $ppt.ActivePresentation.Slides.Count )

# Specify the 
$ppt.ActiveWindow.View.PasteSpecial( "ppPasteOLEObject", "msoFalse",  "", 0, "", "msoFalse")

见   MSDN Interop Docs 并感谢这个例子:   Paste Excel Chart into Powerpoint using VBA

答案 1 :(得分:0)

我在频道中看到了你的问题。 这对我有用:

$presentation = $ppt.Presentations.Open($ifile)
$sl = $presentation.Slides.Add(1, $ppLayoutBlank) 
$shape = $sl.shapes.paste()