placeholder API
| |
| |
| prs = Presentation() |
| slide = prs.slides.add_slide(prs.slide_layouts[8]) |
| |
| for shape in slide.placeholders: |
| print('%d %s' % (shape.placeholder_format.idx, shape.name)) |
| |
| slide.placeholders[2].name |
| |
| |
| |
| |
| |
| |
| |
| placeholder.placeholder_format.type |
| placeholder.insert_picture('my-image.png') |
| |
| |
Text API
| |
| |
| shape.has_text_frame |
| |
| |
| text_frame = shape.text_frame |
| text_frame.clear() |
| |
| p = text_frame.paragraphs[0] |
| p.text = paragraph_strs[0] |
| |
| for para_str in paragraph_strs[1:]: |
| p = text_frame.add_paragraph() |
| p.text = para_str |
| |
| |
| shape.text = 'foobar' |
| |
| text_frame = shape.text_frame |
| text_frame.clear() |
| p = text_frame.paragraphs[0] |
| run = p.add_run() |
| run.text = 'foobar' |
| |
| |
| from pptx.util import Inches |
| from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE |
| |
| text_frame = shape.text_frame |
| text_frame.text = 'Spam, eggs, and spam' |
| text_frame.margin_bottom = Inches(0.08) |
| text_frame.margin_left = 0 |
| text_frame.vertical_anchor = MSO_ANCHOR.TOP |
| text_frame.word_wrap = False |
| text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT |
| |
| |
| from pptx.enum.text import PP_ALIGN |
| |
| paragraph_strs = [ |
| 'Egg, bacon, sausage and spam.', |
| 'Spam, bacon, sausage and spam.', |
| 'Spam, egg, spam, spam, bacon and spam.' |
| ] |
| |
| text_frame = shape.text_frame |
| text_frame.clear() |
| |
| p = text_frame.paragraphs[0] |
| p.text = paragraph_strs[0] |
| p.alignment = PP_ALIGN.LEFT |
| |
| for para_str in paragraph_strs[1:]: |
| p = text_frame.add_paragraph() |
| p.text = para_str |
| p.alignment = PP_ALIGN.LEFT |
| p.level = 1 |
| |
| |
| from pptx.dml.color import RGBColor |
| from pptx.enum.dml import MSO_THEME_COLOR |
| from pptx.util import Pt |
| |
| text_frame = shape.text_frame |
| text_frame.clear() |
| |
| p = text_frame.paragraphs[0] |
| run = p.add_run() |
| run.text = 'Spam, eggs, and spam' |
| |
| font = run.font |
| font.name = 'Calibri' |
| font.size = Pt(18) |
| font.bold = True |
| font.italic = None |
| font.color.theme_color = MSO_THEME_COLOR.ACCENT_1 |
| |
| run.hyperlink.address = 'https://github.com/scanny/python-pptx' |
| |
| font.color.rgb = RGBColor(0xFF, 0x7F, 0x50) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)