在 PowerShell 中从 PowerPoint 创建 mp4
Create mp4 from PowerPoint in PowerShell
我正在处理一个需要将 PowerPoint 演示文稿自动导出为 .mp4 格式的项目。我已经想出如何使用 powershell 以 .mp4 格式保存 PowerPoint,但我无法找到任何文档来说明如何仅使用 powershell 更改幻灯片在视频中保留在屏幕上的秒数。
当前代码:
$Application = New-Object -ComObject powerpoint.application
$Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$ThemePath = "C:\Users\Theme.potx"
$PPTXPath = "C:\Users\ExistingPresentation.pptx"
$SavePath = "C:\Users\MyPresentation.mp4"
$Presentation = $Application.Presentations.Open($ReportPath)
--Applies a theme for the slides
$Presentation.ApplyTemplate($ThemePath)
--Saves as a Video
$Presentation.SaveAs($SavePath, 39)
$Presentation.Close()
我的目标是什么:
编辑:我在 Windows PowerPoint 中找到了一个库,它似乎包含一个 类 的库,可用于更改其成员。其中之一是 "powerpoint.application," 根据 Theo 的建议,理论上应该可以使用以下脚本,但我得到了一个错误。
$SlideShowTransition = New-Object -ComObject powerpoint.SlideShowTransition
$SlideShowTransition.AdvanceOnTime = $True
$SlideShowTransition.AdvanceTime = 10
New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:13
+ $Whatever = New-Object -ComObject powerpoint.SlideShowTransition
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
这是另一个直接来自环境的 screenshot。由于某种原因,SlideShowTransition 没有出现。我可能缺少参考...?
我认为您不应该在不使用 $Presentation 的情况下创建 $SlideShowTransition,因为后者代表实际的演示文稿,否则您无法在其上设置任何内容。
请参阅 MS official doc 上的示例,它如何使用 ActivePresentation 进行设置。
工作原理:如果您在左侧搜索框中搜索 ActivePresentation,您会看到它位于应用程序下。所以引用它的路径是 Application.ActivePresentation.Slides 之后你可以尝试 Theo 的方法。我认为您只有 1 个打开的演示文稿是活动的。如果不是,您需要在文档中深入挖掘以激活您的 $Presentation。
我正在处理一个需要将 PowerPoint 演示文稿自动导出为 .mp4 格式的项目。我已经想出如何使用 powershell 以 .mp4 格式保存 PowerPoint,但我无法找到任何文档来说明如何仅使用 powershell 更改幻灯片在视频中保留在屏幕上的秒数。
当前代码:
$Application = New-Object -ComObject powerpoint.application
$Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
$ThemePath = "C:\Users\Theme.potx"
$PPTXPath = "C:\Users\ExistingPresentation.pptx"
$SavePath = "C:\Users\MyPresentation.mp4"
$Presentation = $Application.Presentations.Open($ReportPath)
--Applies a theme for the slides
$Presentation.ApplyTemplate($ThemePath)
--Saves as a Video
$Presentation.SaveAs($SavePath, 39)
$Presentation.Close()
我的目标是什么:
编辑:我在 Windows PowerPoint 中找到了一个库,它似乎包含一个 类 的库,可用于更改其成员。其中之一是 "powerpoint.application," 根据 Theo 的建议,理论上应该可以使用以下脚本,但我得到了一个错误。
$SlideShowTransition = New-Object -ComObject powerpoint.SlideShowTransition
$SlideShowTransition.AdvanceOnTime = $True
$SlideShowTransition.AdvanceTime = 10
New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:13
+ $Whatever = New-Object -ComObject powerpoint.SlideShowTransition
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
这是另一个直接来自环境的 screenshot。由于某种原因,SlideShowTransition 没有出现。我可能缺少参考...?
我认为您不应该在不使用 $Presentation 的情况下创建 $SlideShowTransition,因为后者代表实际的演示文稿,否则您无法在其上设置任何内容。
请参阅 MS official doc 上的示例,它如何使用 ActivePresentation 进行设置。
工作原理:如果您在左侧搜索框中搜索 ActivePresentation,您会看到它位于应用程序下。所以引用它的路径是 Application.ActivePresentation.Slides 之后你可以尝试 Theo 的方法。我认为您只有 1 个打开的演示文稿是活动的。如果不是,您需要在文档中深入挖掘以激活您的 $Presentation。