2010-11-03 37 views
0

我嘗試在PowerPoint 2007中使用PowerShell 2.0腳本中的ExportAsFixedFormat。只有前兩個參數是必需的,但這是行不通的。Powershell中的PowerPoint ExportAsFixedFormat

我總是得到:

異常調用 「ExportAsFixedFormat」 與 「2」 參數(S): 「類型不匹配(從HRESULT 異常:0x80020005(DISP_E_TYPEMISMATCH))」

我讀過所有參數都必須指定它的功能,但這也不起作用。順便說一句,同樣的方法適用於我在Word 2007和Excel 2007

那麼,什麼是錯的:

Add-type -AssemblyName Office 
Add-type -AssemblyName Microsoft.Office.Interop.PowerPoint 

$p = new-object -comobject powerpoint.application 
$p.visible = 1 
$document = $p.presentations.open('somefile.ppt') 


$document.ExportAsFixedFormat($Path, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::ppFixedFormatTypePDF, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]::ppFixedFormatIntentScreen, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
[Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder]::ppPrintHandoutVerticalFirst, 
[Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]::ppPrintOutputSlides, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
$null, 
[Microsoft.Office.Interop.PowerPoint.PpPrintRangeType]::ppPrintAll, 
[System.Reflection.Missing]::Value, 
$true, 
$true, 
$true, 
$true, 
$false, 
[System.Reflection.Missing]::Value) 

回答

0

變化$null[System.Reflection.Missing]::Value

+0

感謝答覆。不幸的是,沒有成功。 – 2010-11-04 16:26:40

1

我意識到這是一個遲到的答案,但我想我已經得到了解決方案。 (我試圖在c#中使用NetOffice調用此方法,並且得到相同的錯誤)

看起來Microsoft Powerpoint中存在一個錯誤(至少在v 2007 & 2010中)。 必須指定PrintRange參數,因爲默認值(0)無效!

所以工作腳本可能類似於:

Add-type -AssemblyName Office 
Add-type -AssemblyName Microsoft.Office.Interop.PowerPoint 

$p = new-object -comobject powerpoint.application 
$p.visible = 1 
$document = $p.presentations.open('somefile.ppt') 
$ranges = $document.PrintOptions.Ranges 
$range = $ranges.Add(1,1) 


$document.ExportAsFixedFormat($Path, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::ppFixedFormatTypePDF, 
[Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]::ppFixedFormatIntentScreen, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
[Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder]::ppPrintHandoutVerticalFirst, 
[Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]::ppPrintOutputSlides, 
[Microsoft.Office.Core.MsoTriState]::msoFalse, 
$range, 
[Microsoft.Office.Interop.PowerPoint.PpPrintRangeType]::ppPrintAll, 
[System.Reflection.Missing]::Value, 
$true, 
$true, 
$true, 
$true, 
$false, 
[System.Reflection.Missing]::Value) 

通知$範圍參數現在是通過

NB - 這個答案從這裏的解決方案適應:https://netoffice.codeplex.com/discussions/449288

+0

有趣 - 但是當ppt被另一種語言調用時,該錯誤不應該表現出來嗎?畢竟,它的COM對於從Powershell中調用它應該沒有什麼特別之處。這就是說,我已經切換到VB.NET,因爲它更適合與MS Office互操作。有些功能需要在Office VB中調用東西,這是動態的,因此與其他.NET語言相比更加困難。 – 2014-04-04 12:59:43

+0

我不認爲從powershell調用它有什麼特別 - 正如我所說我使用NetOffice(這是一個很好的辦公室互操作程序集替代方案)在c#程序中遇到了這個問題,所以我假設問題是通用的 – 2014-04-04 13:21:22