码迷,mamicode.com
首页 > 编程语言 > 详细

python - pptx

时间:2017-11-29 21:53:48      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:slide   text   [1]   imp   shape   ble   his   graph   box   

from pptx import Presentation
from pptx.util import Pt
from docx.shared import Inches

prs=Presentation()
slide=prs.slides.add_slide(prs.slide_layouts[1])
shape_txt=slide.shapes.placeholders
shape_txt[0].text=‘this is title‘
shape_txt[1].text=‘this is sub title‘
new_para=shape_txt[1].text_frame.add_paragraph()

def para_set(new_para,txt,level=1,size=22,bold=False,italic=False,underline=False):
new_para.text = txt
new_para.level = level
new_para.font.size = Pt(size)
new_para.font.bold = bold
new_para.font.italic = italic
new_para.font.underline = underline
def add_txt_box(slide,txt,left,top,width,height):
textbox=slide.shapes.add_textbox(left,top,width,height)
textbox.text=txt
new_para=textbox.text_frame.add_paragraph()
new_para.text="This is a second paragraph!"
def add_pic(slide,pic,left,top,width,height):
slide.shapes.add_picture(pic,left,top,width,height)
table=slide.shapes.add_table(2,3,Inches(3.5),Inches(4.5),Inches(5),Inches(1))
para_set(new_para,‘新段落‘)
add_txt_box(slide,‘new text‘,Inches(4),Inches(1.8),Inches(5),Inches(1))
add_pic(slide,‘123.png‘,Inches(1),Inches(4.5),Inches(2),Inches(2))
prs.save(‘test.pptx‘)

python - pptx

标签:slide   text   [1]   imp   shape   ble   his   graph   box   

原文地址:http://www.cnblogs.com/xiesongyou/p/7922750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!