PowerPoint 2007 SP2,PowerShell中的ExportAsFixedFormat? [英] PowerPoint 2007 SP2, ExportAsFixedFormat in PowerShell?

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

问题描述

昨天我正试图将一组PPT批量转换为一个PDF,我决定看看PowerShell,因为它已经在我的HD上呆了一段时间了.

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.

这是我想出的代码.

$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) 

2用于PDF

由于强力"方法不起作用(类型不匹配"),我尝试使用以下方式导入枚举类型

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...

此外,SaveAs可以很好地与

Also, SaveAs works fine with

$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF

我在做什么错了?

更新

相关文档:

  • PpFixedFormatType Enumeration
  • ExportAsFixedFormat Method

这是完整的错误消息

$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

推荐答案

我在Python中遇到了相同的问题.尝试按照Stefan Schukat的解决方案中所述指定PrintRange参数:

I've come across the same problem in Python. Try specifying PrintRange argument as said in solution by Stefan Schukat:

这是Powerpoint中的错误.它定义了"[[,可选, defaultvalue(0)] PrintRange * PrintRange导致生成 python包装器中的"PrintRange = 0".因此,您将获得 调用方法时发生错误.所以没问题.解决方法 调用PrintRange = None的方法,因为None是一个重要的COM对象. 例如. Presentation.ExportAsFixedFormat(pptFile +'.pdf', win32com.client.constants.ppFixedFormatTypePDF, win32com.client.constants.ppFixedFormatIntentScreen,PrintRange =无) 应该可以.

This is a bug in Powerpoint. It defines "[in, optional, defaultvalue(0)] PrintRange* PrintRange" which leads to the generation of "PrintRange=0" in the python wrapper. Therefore you'll get the error when calling the method. So no problem of makepy. Workaround call the method with PrintRange=None since None is a vali COM object. E.g. presentation.ExportAsFixedFormat(pptFile+'.pdf', win32com.client.constants.ppFixedFormatTypePDF, win32com.client.constants.ppFixedFormatIntentScreen, PrintRange=None) should work.

来源:使用PowerPoint 2007的导出功能时类型不匹配

我一点都不了解PowerShell,但已经找到了一个可行的示例:

I don't know PowerShell at all but have worked out a working example:

$p.ActivePresentation.PrintOptions.Ranges.Add(1,1)
$r = $p.ActivePresentation.PrintOptions.Ranges.Item(1)
$document.ExportAsFixedFormat('D:\\ps.pdf', 2, 1, 0, 1, 1, 0, $r)

这不是完整的解决方案,但导出已完成.它以某种方式导出完整的演示文稿,而不仅仅是幻灯片编号. 1,正如我所想. P.S.哦.这是相同的解决方案

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

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

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