Hier, j'essayais de convertir par lots un groupe de PPT en PDF pour un ami, et j'ai décidé de jeter un coup d'œil à PowerShell, puisqu'il est resté sur mon HD pendant un moment.PowerPoint 2007 SP2, ExportAsFixedFormat dans PowerShell?
Voici le code que j'ai trouvé.
$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)
Puisque la méthode "force brute" ne fonctionnait pas ("incompatibilité de type") J'ai essayé d'importer le type ENUM avec
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat('\some\newfile.pdf', $pptypepdf)
La chose étrange est que il jette encore une erreur "incompatibilité de type" ...
En outre, SaveAs fonctionne très bien avec
$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF
Qu'est-ce que je fais mal?
Mise à jour
La documentation pertinente:
Voici le message d'erreur complet
$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
Quelle est l'erreur exacte? J'ai vérifié MSDN, et la documentation sur cette méthode semble être fausse pour cet argument. Et je ne peux même pas trouver cette énumération sur MSDN! – JasonMArcher
J'ai édité la question avec les détails pertinents, merci –
Avez-vous essayé un appel donnant tous les paramètres facultatifs? –