PowerPoint ExportAsFixedFormat在Powershell中 [英] PowerPoint ExportAsFixedFormat in Powershell

查看:559
本文介绍了PowerPoint ExportAsFixedFormat在Powershell中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在PowerShell 2.0脚本中使用PowerPoint 2007中的 ExportAsFixedFormat 。只需要前两个参数,但这不行。

I try to use the ExportAsFixedFormat in PowerPoint 2007 from a PowerShell 2.0 script. Only the first two arguments are required, but that won't work.

我总是得到:


异常调用ExportAsFixedFormat与2
参数:类型不匹配(
从HRESULT异常:0x80020005(DISP_E_TYPEMISMATCH))

Exception calling "ExportAsFixedFormat" with "2" argument(s): "Type mismatch. ( Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

我已经读过所有的参数都必须被指定才能运行,但是也不行。 BTW,相同的方法在Word 2007和Excel 2007中适用于我。

I've read that all arguments have to be specified for it to function, but that doesn't work either. BTW, the same method works for me in Word 2007 and 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)


推荐答案

我意识到这是一个迟到的答案,但我想我有解决方案。 (我试图使用NetOffice在c#中调用此方法,并得到相同的错误)

I realise this is a late answer, but I think I've got the solution. (I was trying to call this method in c# using NetOffice, and getting the same error)

似乎Microsoft Powerpoint中有一个错误(至少在v 2007中& 2010)。
必须指定PrintRange参数,因为默认值(0)无效!

It appears that there is a bug in Microsoft Powerpoint (At least in v 2007 & 2010). The PrintRange parameter must be specified, because the default (0) is invalid!

所以一个工作脚本可能如下所示:

So a working script might look like:

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)

注意$ range参数现在被传入。

notice the $range parameter is now passed in.

NB - 这个答案是从解决方案这里: https://netoffice.codeplex.com/discussions/449288

NB - this answer is adapted from the solution here: https://netoffice.codeplex.com/discussions/449288

这篇关于PowerPoint ExportAsFixedFormat在Powershell中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆