我想更改 pptx 演示文稿的标题和正文的字体大小。我试图通过title_shape.font = Pt(15)and设置它body_shape.font = Pt(10),但这不起作用。这是我的代码:from pptx import Presentation, util, textfrom pptx.util import Cm, Ptimport fnmatchimport osimport contentOf_pptx as contOfPres# ..............# Generate presentation# ..............prs = Presentation()#blank_slide_layout = prs.slide_layouts[6] #blank layout, see slide layout in powerpointtitle_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.shapestitle_shape = shapes.titletitle_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_frametf.text = 'Test SubText'# ----------------------------------# Store pptx# ----------------------------------prs.save('C:\\tests\\test_pptx_python.pptx')
2 回答
慕仙森
TA贡献1827条经验 获得超7个赞
这是一个对我有用的简单方法:
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)
添加回答
举报
0/150
提交
取消