PowerPoint 2007 SP2، Exportasfixedformat في PowerShell؟
-
23-08-2019 - |
سؤال
بالأمس كنت أحاول الدفعي تحويل مجموعة من ملفات PPTS إلى ملفات PDF لصديق، وقررت إلقاء نظرة على PowerShell، لأنه كان يجلس على HD لفترة من الوقت.
إليك الرمز الذي وصلت إليه.
$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)
الشيء الغريب هنا هو أنه لا يزال يلقي خطأ "عدم تطابق النوع" ...
أيضا، غفوة يعمل بشكل جيد مع
$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF
ما الخطأ الذي افعله؟
تحديث
الوثائق ذات الصلة:
إليك رسالة الخطأ الكاملة
$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
لا يوجد حل صحيح
نصائح أخرى
لقد صادفت نفس المشكلة في بيثون. حاول تحديد PrintRange
حجة كما قال في حل ستيفان شركات:
هذا خطأ في PowerPoint. يحدد [في، اختياري، DefaultValue (0)] printrange * printrange" الذي يؤدي إلى جيل "printrange = 0" في غلاف بيثون. لذلك ستحصل على الخطأ عند استدعاء الطريقة. لذلك لا مشكلة مايببي. اتصل بالطريقة مع printrange = لا شيء لأنه لا يوجد كائن VALI COM. على سبيل المثال formation.exportasfixedformat (pptfile + '. pdf'، win32com.client.constants.ppfixedformattypepdf، win32com.client.constants.ppfixedformatintentscreen، printrange = none) يجب أن تعمل.
المصدر: عدم تطابق النوع عند استخدام Fuction تصدير PowerPoint 2007
لا أعرف PowerShell على الإطلاق ولكنها عملت بمثال عمل:
$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، كما اعتقدت. سكرتير خاص أوه. هنا هو نفسه المحلول