如何更改python pptx对象的字体大小

我想更改 pptx 演示文稿的标题和正文的字体大小。我试图通过title_shape.font = Pt(15)and设置它body_shape.font = Pt(10),但这不起作用。


这是我的代码:


from pptx import Presentation, util, text

from pptx.util import Cm, Pt

import fnmatch

import os


import contentOf_pptx as contOfPres



# ..............

# Generate presentation

# ..............

prs = Presentation()

#blank_slide_layout = prs.slide_layouts[6] #blank layout, see slide layout in powerpoint

title_only = prs.slide_layouts[5] #title only, see slide layout in powerpoint 




# ..............

# set layout

# ..............

bullet_slide_layout = prs.slide_layouts[1]

slide = prs.slides.add_slide(bullet_slide_layout)

shapes = slide.shapes


title_shape = shapes.title

title_shape.font = Pt(15)


body_shape = shapes.placeholders[1]

body_shape.font = Pt(10)


# ..............

# set relevant text objects

# ..............

title_shape.text = 'Test Title'


tf = body_shape.text_frame

tf.text = 'Test SubText'



# ----------------------------------

# Store pptx

# ----------------------------------

prs.save('C:\\tests\\test_pptx_python.pptx')


慕慕森
浏览 447回答 2
2回答

慕仙森

这是一个对我有用的简单方法:slide = prs.slides.add_slide(blank_slide_layout)slide.shapes.title.text = "The Title of My Slide"slide.shapes.title.text_frame.paragraphs[0].font.size = Pt(15)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python