PowerPoint
Microsoft 演示文稿图形产品系列,提供用于创建演示文稿和添加图形效果(如多媒体对象和带文本的特殊效果)的工具。
9 个问题
我的需求是通过自动排练计时来将pptx导出为mp4,但是我在使用pywin32自动排练计时的时候遇到了问题,代码如下
powerpoint = win32.Dispatch('PowerPoint.Application')
powerpoint.Visible = True
# powerpoint.ShowWindowsInTaskbar = True
presentation = powerpoint.Presentations.Open(r"C:\Users\Administrator\Desktop\ChatPPT_1691750176987.pptx")
slide_count = presentation.Slides.Count
presentation.SlideShowSettings.AdvanceMode = 3
presentation.SlideShowSettings.StartingSlide = 1
presentation.SlideShowSettings.EndingSlide = slide_count
presentation.SlideShowSettings.ShowWithNarration = False
slide_show = presentation.SlideShowSettings.Run()
view = slide_show.View
view.AcceleratorsEnabled = False
# 函数:手动翻页
def go_to_next_slide():
view.Next()
def go_to_slide(index: int):
view.GotoSlide(index)
for index in range(slide_count):
time.sleep(0.1) # 等待2秒
# print(index + 1)
go_to_slide(index + 1)
view.Exit()
print('over')
当代码执行到view.Exit()时,会弹出上图的框并阻塞后续操作,我该如何修改我的代码使其可以自动保留幻灯片计时
Hi,
不知您是否尝试过修改 AdvanceMode 的值来控制幻灯片的行为?
import win32com.client as win32
import time
powerpoint = win32.Dispatch('PowerPoint.Application')
powerpoint.Visible = True
# powerpoint.ShowWindowsInTaskbar = True
presentation = powerpoint.Presentations.Open(r"path_to_your_slide.pptx")
slide_count = presentation.Slides.Count
presentation.SlideShowSettings.AdvanceMode = 1
presentation.SlideShowSettings.StartingSlide = 1
presentation.SlideShowSettings.EndingSlide = slide_count
presentation.SlideShowSettings.ShowWithNarration = False
slide_show = presentation.SlideShowSettings.Run()
view = slide_show.View
view.AcceleratorsEnabled = False
# 函数:手动翻页
def go_to_next_slide():
view.Next()
def go_to_slide(index: int):
view.GotoSlide(index)
for index in range(slide_count):
time.sleep(0.5) # 等待0.5秒
# print(index + 1)
go_to_slide(index + 1)
view.Exit()
presentation.close()
print('over')
Regards, Alex