昨天我試圖批量將一組PPT轉換爲一個朋友的PDF文件,我決定看看PowerShell,因爲它一直在我的HD上。PowerPoint 2007 SP2,PowerShell中的ExportAsFixedFormat?
這是我想出的代碼。
$p = new-object -comobject powerpoint.application
# I actually don't know why I have to set the window to visible,
# but it doesn't work otherwise, anyway, it's not the real problem I have
$p.visible = 1
$f = $p.presentations.open('\some\file.ppt')
$f.ExportAsFixedFormat('\some\newfile.pdf', 2)
自「蠻力」方法不起作用(「類型不匹配」),我試圖用
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat('\some\newfile.pdf', $pptypepdf)
這裏奇怪的是,進口枚舉類型它仍然會拋出「類型不匹配」的錯誤...
另外,SaveAs可以正常工作
$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF
我在做什麼錯?
更新
相關文章:
下面是完整的錯誤消息
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat($filepath, $pptypepdf)
Exception calling "ExportAsFixedFormat" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
At line:1 char:23
+ $f.ExportAsFixedFormat <<<< ($filepath, $pptypepdf)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
什麼是確切的錯誤?我查了MSDN,關於這個方法的文檔似乎對這個參數是錯誤的。而且我甚至無法在MSDN上找到枚舉! – JasonMArcher 2009-05-21 22:16:23