首页 > 其他 > 详细

向ppt里插入图片和表格

时间:2020-02-21 21:37:45      阅读:126      评论:0      收藏:0      [点我收藏+]

# 导入库
from pptx import Presentation
from pptx.util import Inches

ppt = Presentation() #新建幻灯片
slide = ppt.slides.add_slide(ppt.slide_layouts[1]) #插入新的幻灯片页面
‘‘‘Picture‘‘‘
# 指定图片的左右边距和高、宽
# left = Inches(1)
# top = Inches(1)
# width = Inches(2)
# height = Inches(2)

# 插入图片
# pic = slide.shapes.add_picture(C:\Users\13375\Desktop\pythonxiaohuangya.jpg‘,left,top,width,height)

# ppt.save(r‘C:\Users\13375\Desktop\python\pptcharutupian.pptx‘)
‘‘‘表格的行列位置‘‘‘
rows = 4
cols = 4
left = Inches(3)
top = Inches(3)
width = Inches(6)
height = Inches(4)

table = slide.shapes.add_table(rows,cols,left,top,width,height).table #插入表格


table.columns[0].width = Inches(1) #设置第一列的宽度为1英寸
table.columns[1].width = Inches(3) # 设置第二列的宽度为3英寸
# 向表格里写入文字
table.cell(0,0).text = ‘1‘ #指定位置写入文本
table.cell(0,1).text = ‘2‘
table.cell(1,0).text = ‘3‘
table.cell(1,1).text = ‘4‘
ppt.save(r‘C:\Users\13375\Desktop\python\tables.pptx‘)

向ppt里插入图片和表格

原文:https://www.cnblogs.com/tomhu/p/12342983.html

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