Powershell 中的 PowerPoint 导出为固定格式
我尝试通过 PowerShell 2.0 脚本在 PowerPoint 2007 中使用 ExportAsFixedFormat
。仅需要前两个参数,但这不起作用。
我总是得到:
使用“2”调用“ExportAsFixedFormat”时出现异常 参数:“类型不匹配。( 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)
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.
I always get:
Exception calling "ExportAsFixedFormat" with "2"
argument(s): "Type mismatch. (
Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
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.
So what is wrong with this:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我意识到这是一个迟到的答案,但我想我已经找到了解决方案。 (我试图使用 NetOffice 在 C# 中调用此方法,并得到相同的错误)
Microsoft Powerpoint 中似乎存在错误(至少在 v 2007 和 2010 中)。
必须指定PrintRange参数,因为默认值(0)无效!
因此,工作脚本可能如下所示:
注意现在传入了 $range 参数。
注意 - 这个答案改编自此处的解决方案: https://netoffice.codeplex.com/discussions/449288
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)
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:
notice the $range parameter is now passed in.
NB - this answer is adapted from the solution here: https://netoffice.codeplex.com/discussions/449288
参数存在两个问题:
[System.Reflection.Missing]::Value
无效。跳过它。代码来自非常完整的示例 https://gist.github.com/allenyllee/5d7c4a16ae0e33375e4a6d25acaeeda2
There were two issues with the parameters:
[System.Reflection.Missing]::Value
is invalid. Just skip it.Code is from very complete example at https://gist.github.com/allenyllee/5d7c4a16ae0e33375e4a6d25acaeeda2
将
$null
更改为[System.Reflection.Missing]::Value
。Change
$null
to[System.Reflection.Missing]::Value
.