ppt里写入文字

from pptx import Presentation
from pptx.util import Inches,Pt

ppt = Presentation()
slide = ppt.slides.add_slide(ppt.slide_layouts[1]) #在ppt中插入一个幻灯片页

body_shape = slide.shapes.placeholders

title_shape = slide.shapes.title
title_shape.text = '这里是标题'
subtitle = slide.shapes.placeholders[1] #取出本页第二个文本框
subtitle.text = '这里是文本框'  #在第二个文本框中写入文字

new_paragraph = body_shape[1].text_frame.add_paragraph()
new_paragraph.text = '新段落'
new_paragraph.font.bold = True #文字加粗
new_paragraph.font.italic = True#文字斜体
new_paragraph.font.size = Pt(15) #文字大小
new_paragraph.font.underline = True #文字下划线


'''新加入一个文本框'''
left = Inches(6)
top = Inches(2)
width = Inches(3)
height = Inches(3)

textbox = slide.shapes.add_textbox(left,top,width,height)
textbox.text = '这是新文本框'
new_para = textbox.text_frame.add_paragraph()
new_para.text = '这是文本框里面的第二段'
ppt.save(r'C:\Users\13375\Desktop\python\model.pptx')


猜你喜欢

转载自www.cnblogs.com/tomhu/p/12342923.html