PowerPoint 2007 SP2,PowerShell 中的 ExportAsFixedFormat?
昨天,我试图为朋友将一组 PPT 批量转换为 PDF,我决定看看 PowerShell,因为它在我的硬盘上已经有一段时间了。
这是我想出的代码。
$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
What am I做错了吗?
更新
相关文档:
- PpFixedFormatType Enumeration
- < a href="http://msdn.microsoft.com/en-us/library/bb231096.aspx" rel="nofollow noreferrer">ExportAsFixedFormat 方法
这是完整的错误消息
$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
Yesterday I was trying to batch convert a group of PPTs into PDFs for a friend, and I decided to have a look at PowerShell, since it's been sitting on my HD for a while.
Here's the code I've come up with.
$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)
Since the "brute force" method didn't work ("type mismatch") I tried to import the enum type with
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat('\some\newfile.pdf', $pptypepdf)
The strange thing here is that it still throws a "type mismatch" error...
Also, SaveAs works fine with
$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF
What am I doing wrong?
Update
Relevant documentation:
Here's the full error message
$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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在Python中也遇到过同样的问题。 尝试指定
PrintRange
参数,如 Stefan Schukat 的解决方案中所述:来源:使用 PowerPoint 2007 的导出功能时键入不匹配
我不知道 PowerShell根本没有,但已经制定了一个工作示例:
这不是完整的解决方案,但导出已完成。 它以某种方式导出完整的演示文稿,而不仅仅是幻灯片编号。 1、和我想的一样。 附言哦。 这是相同的解决方案
I've come across the same problem in Python. Try specifying
PrintRange
argument as said in solution by Stefan Schukat:Source: Type mismatch when using export fuction of PowerPoint 2007
I don't know PowerShell at all but have worked out a working example:
This isn't a full solution, but exporting is done. It somehow exports full presentation, not only slide no. 1, as I thought. P.S. Oh. Here's the same solution