2013-10-24 35 views
0

我目前正在嘗試使用PowerShell創建Powerpoint中的日曆。我想要做的是插入幻燈片幻燈片。此表格代表一月份的月份,它包含一週中的天數等。如何使用PowerShell創建Powerpoint表

我做了一些調查,發現了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

+0

顯示您在嘗試將VBS轉換爲PowerShell時創建的代碼。 – alroc

+0

@arloc 因爲我對powershell很陌生,所以我沒有做太多的工作,但是這裏是我的嘗試:http://pastebin.com/8sqQptFb – untotz

+0

你以什麼方式「不成功」?描述你的最終目標是什麼,你做了什麼,你得到了什麼,以及你卡在哪裏/事情沒有按預期工作。在處理應用程序可見性方面至少有一個錯誤(提示:比較'$ objPPT.Visible'和$ $ xl.Visible') – alroc

回答

0

我看到你的問題的渠道。 這工作對我來說:

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

嗨,感謝您的回覆,它的工作,但我不得不使用'$ range.copyPicture()'而不是'$ range.copy()'。 – untotz

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