from pptx importPresentationfrom pptx.util importPt, Inches

prs=Presentation()

slide= prs.slides.add_slide(prs.slide_layouts[1])#添加空白页PPT

body_shape=slide.shapes.placeholders

body_shape[0].text= 'this is placeholders[0]' #在第一个文本框中文字框架内添加文字

body_shape[1].text = 'this is placeholders[1]' #在第二个文本框中文字框架内添加文字

print(len(slide.shapes.placeholders))

new_paragraph= body_shape[1].text_frame.add_paragraph() #在第二个shape中的文本框架中添加新段落

new_paragraph.text = 'add_paragraph' #新段落中文字

new_paragraph.font.bold = True #文字加粗

new_paragraph.font.italic = True #文字斜体

new_paragraph.font.size = Pt(15) #文字大小

new_paragraph.font.underline = True #文字下划线

new_paragraph.level = 1 #新段落的级别

left= top = width = height = Inches(5) #预设位置及大小

textbox = slide.shapes.add_textbox(left, top, width, height) #left,top为相对位置,width,height为文本框大小

textbox.text = 'this is a new textbox' #文本框中文字

new_para = textbox.text_frame.add_paragraph() #在新文本框中添加段落

new_para.text = 'this is second para in textbox' #段落文字

img_path= 'dog.png' #文件路径

left, top, width, height = Inches(1), Inches(4.5), Inches(2), Inches(2) #预设位置及大小

pic = slide.shapes.add_picture(img_path, left, top, width, height) #在指定位置按预设值添加图片

from pptx.enum.shapes importMSO_AUTO_SHAPE_TYPE

left, top, width, height= Inches(1), Inches(3), Inches(1.8), Inches(1) #预设位置及大小

shape = slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.PENTAGON, left, top, width, height) #在指定位置按预设值添加类型为PENTAGON的形状

shape.text = 'Step 1'

for n in range(2, 6):

left= left + width - Inches(0.3)

shape=slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.CHEVRON, left, top, width, height)

shape.text= 'Step{}'.format(n)

rows, cols, left, top, width, height= 2, 2, Inches(3.5), Inches(4.5), Inches(6), Inches(0.8)

table= slide.shapes.add_table(rows, cols, left, top, width, height).table #添加表格,并取表格类

table.columns[0].width = Inches(2.0) #第一纵列宽度

table.columns[1].width = Inches(4.0) #第二纵列宽度

table.cell(0, 0).text = 'text00' #指定位置写入文本

table.cell(0, 1).text = 'text01'table.cell(1, 0).text = 'text10'table.cell(1, 1).text = 'text11'

from pptx.chart.data importChartDatafrom pptx.enum.chart importXL_CHART_TYPEfrom pptx.enum.chart importXL_TICK_MARKfrom pptx.dml.color importRGBColorfrom pptx.enum.chart importXL_DATA_LABEL_POSITIONfrom pptx.enum.chart importXL_LEGEND_POSITION

slide= prs.slides.add_slide(prs.slide_layouts[6]) #在幻灯片中加入一页6号风格(空白)幻灯片

#chart1 左上方图

x, y, cx, cy = Inches(0.5), Inches(0.5), Inches(4), Inches(3) #按英尺标准指定x,y值

chart_data= ChartData() #图表data类

chart_data.categories= [u'A班级得分率', u'B班级得分率'] #图表加入两栏

chart_data.add_series(u'得分率对比', (80.5, 60.5)) #在两栏分别填入数据

graphic_frame=slide.shapes.add_chart(

XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data

)#add_chart(图表类型,xy表示图表位置,cx cy表示图表宽高,并且插入chart_data中规定好的数据)

chart= graphic_frame.chart #从生成的图表中取出图表类

chart.chart_style = 21 #图表整体颜色风格

chart.has_title= True #图表是否含有标题,默认为False

chart.chart_title.text_frame.clear() #清除原标题

new_paragraph = chart.chart_title.text_frame.add_paragraph() #添加一行新标题

new_paragraph.text = '得分率对比' #新标题

new_paragraph.font.size = Pt(15) #新标题字体大小

category_axis= chart.category_axis #category_axis 为chart的category控制类

category_axis.has_major_gridlines = True #是否显示纵轴线

category_axis.tick_labels.font.italic = True #tick_labels为图表下标签,置为斜体

category_axis.tick_labels.font.size = Pt(15) #下标签字体大小

category_axis.tick_labels.font.color.rgb = RGBColor(255, 0, 0) #标签字体颜色

value_axis= chart.value_axis #value_axis 为chart的value控制类

value_axis.maximum_scale = 100.0 #纵坐标最大值

value_axis.minimum_scale = 0.0 #纵坐标最小值

value_axis.minor_tick_mark =XL_TICK_MARK.CROSS

value_axis.has_minor_gridlines=True

tick_labels= value_axis.tick_labels #tick_labels 为chart的纵轴标签控制类

tick_labels.number_format = '0%' #标签显示样式

tick_labels.font.bold = True #字体加粗

tick_labels.font.size = Pt(14) #字体大小

tick_labels.font.color.rgb = RGBColor(0, 255, 0) #标签颜色

plot= chart.plots[0] #取图表中第一个plot

plot.has_data_labels = True #是否显示数据标签

data_labels = plot.data_labels #数据标签控制类

data_labels.font.size = Pt(13) #字体大小

data_labels.font.color.rgb = RGBColor(0, 0, 255) #字体颜色

data_labels.position = XL_DATA_LABEL_POSITION.INSIDE_END #字体位置

#chart 2 左下方图

x, y, cx, cy = Inches(0.5), Inches(3.5), Inches(4), Inches(3) #按英尺标准指定x,y值

chart_data =ChartData()

chart_data.categories= ['A', 'B', 'C', 'D']

chart_data.add_series(u'A班级选项占比', (80, 10, 9, 10))

chart=slide.shapes.add_chart(

XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data

).chart#PIE为饼状图

chart.has_legend= True #是否含有下方的说明

chart.legend.position =XL_LEGEND_POSITION.BOTTOM

chart.legend.horz_offset= 0 #说明位移量 [-1, 1] 默认为0

chart.plots[0].has_data_labels= True #饼中是否写入数值

data_labels =chart.plots[0].data_labels

data_labels.number_format= '0%' #数值显示格式

data_labels.position = XL_DATA_LABEL_POSITION.INSIDE_END #数值布局方式

chart.has_title=True

chart.chart_title.text_frame.clear()#清除原标题

new_paragraph = chart.chart_title.text_frame.add_paragraph() #添加一行新标题

new_paragraph.text = 'A班级选项占比' #新标题

new_paragraph.font.size = Pt(13) #新标题字体大小

#chart 3 右下方图

x, y, cx, cy = Inches(5.5), Inches(4), Inches(4), Inches(3) #按英尺标准指定x,y值

chart_data =ChartData()

chart_data.categories= ['A', 'B', 'C', 'D']

chart_data.add_series(u'B班级选项占比', (0.1, 0.2, 0.3, 0.4))

chart=slide.shapes.add_chart(

XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data

).chart

chart.has_legend=True

chart.legend.position=XL_LEGEND_POSITION.BOTTOM

chart.plots[0].has_data_labels=True

data_labels=chart.plots[0].data_labels

data_labels.number_format= '0%'data_labels.position=XL_DATA_LABEL_POSITION.INSIDE_END

chart.has_title=True

chart.chart_title.text_frame.clear()#清除原标题

new_paragraph = chart.chart_title.text_frame.add_paragraph() #添加一行新标题

new_paragraph.text = 'B班级选项占比' #新标题

new_paragraph.font.size = Pt(13) #新标题字体大小

#chart 4 右上方图

x, y, cx, cy = Inches(5.5), Inches(0.5), Inches(4), Inches(3)

chart_data=ChartData()

chart_data.categories= ['0', '1-3', '4-6', '7-9']

chart_data.add_series('', (50, 18, 30, 34))

chart=slide.shapes.add_chart(

XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data

).chart

chart.has_legend=True

chart.legend.position=XL_LEGEND_POSITION.BOTTOM

chart.legend.font.size= Pt(13)

chart.plots[0].has_data_labels=True

data_labels=chart.plots[0].data_labels

data_labels.number_format= '0%'data_labels.position=XL_DATA_LABEL_POSITION.INSIDE_END

chart.has_title=True

chart.chart_title.text_frame.clear()

new_title=chart.chart_title.text_frame.add_paragraph()

new_title.text= '得分占比'new_title.font.size= Pt(13)

prs.save('python-pptx.pptx')

从演示文稿中的幻灯片中提取所有文本from pptx importPresentation

prs= Presentation('教育行业通案模板 1.pptx')#text_runs will be populated with a list of strings,#one for each text run in presentation

text_runs =[]for slide inprs.slides:for shape inslide.shapes:if notshape.has_text_frame:continue

for paragraph inshape.text_frame.paragraphs:for run inparagraph.runs:

text_runs.append(run.text)print(text_runs)

python使用演示文稿-python 操作PPT练习相关推荐

  1. python使用演示文稿-Python如意金箍棒演示幻灯片.pyw

    1 """ 2 第九课 如意金箍棒(屏幕与方向)3 """ 4 from sprites import * 5 6 s = '第九课 如意金 ...

  2. 五年级下册计算机课ppt课件ppt课件,小学信息技术浙摄影版五年级下册第12课 制作演示文稿课堂教学ppt课件...

    这是一份小学信息技术浙摄影版五年级下册第12课 制作演示文稿课堂教学ppt课件,文件包含第12课制作演示文稿课件pptx.第12课制作演示文稿教学设计doc等2份课件配套教学资源,其中PPT共8页, ...

  3. ppt编辑器android,演示文稿编辑器 PPTWork PPT 幻灯片_v1.7.5

    介绍:使用支持 Microsoft Powerpoint 和 LibreOffice ODP 格式的在线编辑器创建和编辑 PPT 演示文稿 PPTWork是一个演示编辑器,您可以在任何桌面编辑器中执行 ...

  4. pptx库ppt演示 python_Python自动化操作PPT看这一篇就够了

    作者:超级大洋葱806 https://tangxing.blog.csdn.net/article/details/109568830 1.PPT自动化能干什么?有什么优势? 它可以代替你自动制作P ...

  5. 计算机二级ppt为客户制作演示文稿,计算机二级ppt真题:制作介绍北京ppt

    1.演示文稿题1具体如图示. 2.[打开]文件夹,选择[PPT素材.docx],点击[选择]选定所有格式类似的文本(无数据),点击[段落],调整[大纲级别]1级.选择[蓝色文本],点击[选择]选定所有 ...

  6. 将 Keynote 演示文稿导出为 PPT 或其他文件格式

    Mac默认的演示文稿是Keynote,但是默认保存的格式在windows下是无法打开的,需要先转换成PPT格式或者其他常用格式才可以. 转换方法 打开演示文稿,然后选取"文件"&g ...

  7. 计算机基础应用软件ppt制作,大学计算机基础_演示文稿制作软件.ppt

    大学计算机基础_演示文稿制作软件资料 插入影片和声音 插入影片 插入声音 播放CD乐曲 录制声音 5.5 演示文稿中的动画和超链接技术 5.5.1 为幻灯片加入动画效果 5.5.2 创建超级链接 为幻 ...

  8. python自动化ppt_python自动化怎么操作ppt?

    社会的不断进步,科技的不断发展,让每个人都越发趋向自动化的社会,大家有没有想过居然可以在工作软件上也实现自动化,是不是非常神奇呢?请大家在惊叹神奇之余,跟着小编一起来感受下吧~ python-pptx ...

  9. 计算机二级ppt为客户制作演示文稿,计算机二级PPT真题:制作日月潭介绍PPT

    1.[第一小题题目如图所示]然后打开[考试文件夹-点击另存为-进行重命名保存]. 2.[第二小题题目如图所示]. 3.[新建幻灯片-第一张版式为标题幻灯片,第二章-标题和内容(CTRL+C,CTRL+ ...

最新文章

  1. vc6静态库的生成和调用
  2. 内核aio_Java面试题BIO、NIO、AIO有什么区别?
  3. ♥看二本学渣如何进腾讯 分享面试经验、职场感悟、硬核知识、大厂内推♥
  4. 汇编语言 把最大值放入max 把最小值放入min_Excel的MAX和MIN,如何用白话弄懂?...
  5. 网络bcc程序测试方案
  6. Python计算机视觉:第八章 图像类容分类
  7. 2019.4.27 人工智能培训安装工作记录
  8. java中set语句_数据步骤中的多个SET / MERGE语句
  9. 京东怎么在线联系客服
  10. 在SpringBoot中优雅的实现定时任务
  11. 老电脑应该怎么重装系统比较好
  12. 个人计算机好用的pdf软件,win10好用的pdf阅读器推荐 推荐几款好用的pdf阅读器
  13. python抖音涨粉代码_抖音最火表白代码
  14. cmsis-dap ubuntu Error: unable to find CMSIS-DAP device
  15. 使用C/C++编程控制LEGO EV3
  16. 计算机应用基础 福师在线作业一,福师《计算机应用基础》在线作业一
  17. 扒开系统调用的三层皮(上)
  18. (原创)贴片电阻封装尺寸
  19. 鸿蒙系统最便宜的手机,鸿蒙手机6月2日上市 手机友商不大可能转投鸿蒙系统
  20. 华为荣耀鸿蒙3.0,2.0解决此设备未获得play保护机制认证框架,安装谷歌Play商店服务框架

热门文章

  1. 浏览器是如何运作【前端必备】
  2. 阿里巴巴和亚马逊“必有一战”,马云能赢吗?
  3. [转]如何在网上查找免费电子书
  4. vue3报错:File was processed with these loaders:
  5. 新手python的自学总结(已拿到百度offer)
  6. 2022年《深圳市新引进博士人才生活补贴工作实施办法》最新政策
  7. 苹果邮件怎么添加qq邮箱_分别在win10自带邮件和iOS上添加QQ邮箱
  8. spi总线 上层调用_spi总线驱动详解
  9. 炉石兄弟 Hearthbuddy 新手教程
  10. 会议音响/全向麦克风国产DSP方案