使用Python从PowerPoint演示中选择幻灯片

发布于 2025-02-03 14:12:28 字数 466 浏览 2 评论 0原文

要从PowerPoint演示文稿中打印特定的幻灯片,基于项目列表,我们使用基本PowerPoint工具Ctrl+F之后:
- 避免幻灯片ID
- 避免第二个幻灯片ID
- 使用这些ID,这需要大量工作量。

我们认为使用Python脚本自动化此任务。

from pptx import Presentation

filename = "C:/Users/RElKassah/Desktop/test.pptx"

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    if slide.shapes ==text:    
        title = slide.shapes.text.find = 'test'
        print(title)

To print specific slides from a PowerPoint presentation, based on a list of items we use the basic PowerPoint tool Ctrl+F following this process:
-save the slide ID
-save the second slide ID
-print with those IDs and that takes a lot of workloads.

We think to automate this task with a Python script.

from pptx import Presentation

filename = "C:/Users/RElKassah/Desktop/test.pptx"

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    if slide.shapes ==text:    
        title = slide.shapes.text.find = 'test'
        print(title)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2025-02-10 14:12:28

在这里,我写了一些简单的循环以在PPTX文件中找到文本,然后打印包含该文本的幻灯片的幻灯片。希望它能有所帮助。

from pptx import Presentation

filename = 'test.pptx'

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            for paragraph in shape.text_frame.paragraphs:
                for run in paragraph.runs:
                    if text in run.text:
                        print(prs.slides.index(slide)+1)

Here I wrote some simple loop to find text inside a pptx file, then print slide number of slides that contain that text. Hope it could help.

from pptx import Presentation

filename = 'test.pptx'

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            for paragraph in shape.text_frame.paragraphs:
                for run in paragraph.runs:
                    if text in run.text:
                        print(prs.slides.index(slide)+1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文