安装pptx

pip install python-pptx
  • Python pptx模块是一个Python库,用于创建和更新Microsoft PowerPoint (.pptx)文件。该模块允许开发人员使用Python代码生成演示文稿、幻灯片和报告等PPT文档。
  • 提取PPT中的文字

    • 这一点在期末看ppt时尤为有效
    • 注意:很有可能有一些睿智在做ppt的时候不断的使用覆盖,拼接,截图等技巧,因此很可能不能将所有的文字都取下来,就像做成背景的水印一样。。。。。。。

实例:

import pptxf = open("Review.docx","w")
prs = pptx.Presentation('Review.pptx')
for slide in prs.slides:for shape in slide.shapes:if hasattr(shape, 'text'):f.write(shape.text)f.write("\n")
f.close()
  • 新建PPT
from pptx import Presentation
from pptx.util import Inches# 创建一个新的 PPT 对象
prs = Presentation()# 添加一个空白幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[0])# 在幻灯片上加入标题
title = slide.shapes.title
title.text = "Python PPTX title"# 在幻灯片上加入副标题
subtitle = slide.placeholders[1]
subtitle.text = "Python PPTX subtitle"# 在幻灯片上添加一个文本框
body_shape = slide.shapes.add_textbox(Inches(1), Inches(2), Inches(8), Inches(2))
tf = body_shape.text_frame
tf.text = "Python PPTX textbox"# 在幻灯片上插入图片
slide = prs.slides.add_slide(prs.slide_layouts[1])
left = Inches(1)
top = Inches(2)
pic = slide.shapes.add_picture('2.png',left, top)# 将 PPT 保存到本地文件
prs.save("example.pptx")

  • 幻灯片不同页数的区别,已插入一个表格为例
  • 如下:
from pptx import Presentation
from pptx.util import Inches# 创建一个幻灯片文档
prs = Presentation()# 添加一个幻灯片
for i in range(0,10):slide = prs.slides.add_slide(prs.slide_layouts[i])# 定义表格行数和列数rows = 2cols = 2# 设置表格的位置和大小left = top = Inches(2.0)width = Inches(6.0)height = Inches(0.8)# 添加一个表格到幻灯片中table = slide.shapes.add_table(rows, cols, left, top, width, height).table# 设置表格的样式和表格中的文本内容table.style = "GRADE TABLE"table.cell(0, 0).text = "NAME"table.cell(0, 1).text = "GRADE"table.cell(1, 0).text = "RIVER"table.cell(1, 1).text = "THE HIGHEST"prs.save('example.pptx')
0
1
2
3
4
5
6
7
8
9
  • 以 LaTeX 语法插入公式
# 添加公式
formula_shape = slide.shapes.add_textbox(Inches(2), Inches(6), Inches(6), Inches(1))
formula_tf = formula_shape.text_frame
formula_tf.text = "Maxwell\u2019s Equations: \n\n$\\nabla \\cdot \\mathbf{E} = \\frac{\\rho}{\\epsilon_0}$\n$\\nabla \\cdot \\mathbf{B} = 0$\n$\\nabla \\times \\mathbf{E} = -\\frac{\\partial\\mathbf{B}}{\\partial t}$\n$\\nabla \\times \\mathbf{B} = \\mu_0\\mathbf{J} + \\mu_0\\epsilon_0\\frac{\\partial\\mathbf{E}}{\\partial t}$"# 设置公式格式
for paragraph in formula_tf.paragraphs:paragraph.alignment = MSO_ANCHOR.MIDDLEparagraph.line_spacing = 1.3for run in paragraph.runs:run.font.size = Inches(0.2)run.font.color.rgb = RGBColor(255, 255, 255)

Python pptx模块相关推荐

  1. python pptx怎么复制ppt_python pptx复制ppt中的某一页并且放在这一页之后

    如题,我有一个模板,我想根据需求复制模板中间的某一页多次,比如复制第五页,然后复制3次,那么第六页,第七页,第八页都是和第五页一模一样的ppt,次数是根据我的需求指定的,使用python pptx模块 ...

  2. python pptx怎么复制ppt_python pptx复制指定页的ppt教程

    如题,我有一个模板,我想根据需求复制模板中间的某一页多次,比如复制第五页,然后复制3次,那么第六页,第七页,第八页都是和第五页一模一样的ppt,次数是根据我的需求指定的,使用python pptx模块 ...

  3. Python Re 模块超全解读!详细

    内行必看!Python Re 模块超全解读! 2019.08.08 18:59:45字数 953阅读 121 re模块下的函数 compile(pattern):创建模式对象 > import ...

  4. python argparse模块_Python argparse模块应用实例解析

    这篇文章主要介绍了Python argparse模块应用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 简介 argparse是python ...

  5. 关于使用python logging模块的几点总结

    关于使用python logging模块的几点总结 使用python的标准日志模块logging可以非常方便地记录日志.Python日志系统非常丰富.添加结构化或非结构化日志输出到python代码,写 ...

  6. python高级-模块(14)

    一.python中的模块 有过C语言编程经验的朋友都知道在C语言中如果要引用sqrt函数,必须用语句#include <math.h>引入math.h这个头文件,否则是无法正常进行调用的. ...

  7. 转载: Python os 模块的功能以及子函数介绍

    原文链接: python之os模块 - 程序生(Codey) - 博客园 https://www.cnblogs.com/cxscode/p/8085326.html 一.Python OS模块介绍 ...

  8. 简单介绍python process模块

    在python中大部分情况需要使用多进程,python提供了multiprocessing模块.multiprocessing模块的功能众多:支持子进程.通信和共享数据.执行不同形式的同步,提供了Pr ...

  9. python io模块_python中的StringIO模块

    原博文 2015-10-23 15:21 − # python中的StringIO模块 标签:python StringIO --- > 此模块主要用于在内存缓冲区中读写数据.模块是用类编写的, ...

最新文章

  1. 【深入浅出MyBatis系列十一】缓存源码分析
  2. java的css的块_JavaWeb--了解CSS
  3. 第三十八期:如何在Windows 10上使用Windows Update目录驱动程序安装打印机
  4. How-to: 利用Visual Studio升级Windows Phone 7工程
  5. [转]C#中的多线程进度条使用
  6. ubuntu下安装matlab及配置vot-toolkit
  7. html 表单 元素 美化,分享10款jQuery的表单元素样式美化插件
  8. python 答题助手_MillionHerosHelper-超级答题助手
  9. 虚拟机win 7 上安装VWware Tools提示升级系统到SP1
  10. 湖南超级计算机研学,以超算之速,跨越弦歌千年 | 建宁实验中学中考励志研学...
  11. TCP 之 SYN_SENT状态
  12. 为什么传统的验证码不再安全
  13. 2009个人年度总结报告
  14. #读书笔记# 《人类简史》Chapter7
  15. 自监督学习(Self-Supervised Learning)
  16. 电脑如何截长图?如何用电脑截取长图——规划全景
  17. Pipeline 基础步骤
  18. ACL2019代码开源论文
  19. 分享一个好用的CSS布局
  20. 《Microsoft Sql server 2008 Internals》读书笔记--第六章Indexes:Internals and Management(3)

热门文章

  1. 【Unity连载】斗兽棋—棋类游戏开发演示(1)
  2. curl检测网页的用法
  3. iphone12绿色好看 ,相比被全民吐槽的蓝色,绿色是怎么做到零差评的
  4. Eplan-中断点(3)
  5. mac idea设置堆大小导致idea无法启动
  6. 基于FPGA的数字电子钟的设计与实现
  7. 关于be of noun的用法
  8. 2023.4.14.吉林长春.晴朗
  9. 怎么寻找微信撤回的图片
  10. OSChina 周四乱弹 ——一周五天在诈尸