我想更改 pptx 演示文稿的標(biāo)題和正文的字體大小。我試圖通過(guò)title_shape.font = Pt(15)and設(shè)置它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貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是一個(gè)對(duì)我有用的簡(jiǎn)單方法:
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)
添加回答
舉報(bào)
0/150
提交
取消