首页 > 编程语言 > 详细

python - pptx

时间:2017-11-29 21:42:42      阅读:367      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!