用python处理ppt中的文字

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

ppt=Presentation()
#在ppt中加入一个幻灯片
slide=ppt.slides.add_slide(ppt.slide_layouts[1])
#第一种
body_shape=slide.shapes.placeholders
body_shape[0].text='这是占位符[0]'
body_shape[1].text='这是占位符[1]'
#第二种
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(2)
top=Inches(2)
width=Inches(3)
height=Inches(3)
textbox=slide.shapes.add_textbox(left,top,width.height)
textbox.text="这是新文本框"
#在文本框里添加新段落
new_par=textbox.text_frame.add_paragraph()
new_par.text='这是文本框里的第二段'

ppt.save('test.pptx'); 

你可能感兴趣的:(学习笔记)