windows7下使用vs2013 7 下用VS2013 Visual Studio 2013 编译li

番茄系统家园 · 2021-08-21 18:14:27

windows7下使用vs2013 7 下用VS2013 Visual Studio 2013 编译li

1、下载工具(版本),安装完成后注意配置环境变量,本机安装目录为C:\

2、为了使用pip工具,将C:\\加入到环境变量中,然后使用pip工具安装--pptx,安装成功,界面如下,如不成功,参考官方安装手册-python-pptx0.6.6documentation

3、为了使用vs2013编译python,直接在vs2013中新建python项目,如果没有安装python-vs2013插件,按照vs2013的提示安装即可,装好之后,界面如下,选择第二个选项PythonApplication

4、具体python代码如下:

#coding:utf-8添上这句,否则不能写中文注释

from

pptximportPresentationfrompptx.utilimportInchesimportos#计算一个文件夹下的文件个数,folderPath为文件夹路径defcomputerFileNumber(folderPath):filecount=0importosforroot,dir,filesinos.walk(folderPath):filecount+=len(files)returnfilecount#每次调用,向一页ppt中插入fileNumber个图片,folderPath为图片所在文件夹#heigth,left,top的定义如下

height

Read/write.IntegerdistancebetweentopandbottomextentsofshapeinEMUs

left

Read/write.Integerdistanceoftheleftedgeofthisshapefromtheleftedgeoftheslide,inEnglishMetricUnits(EMU)

top

Read/write.Integerdistanceofthetopedgeofthisshapefromthetopedgeoftheslide,inEnglishMetricUnits(EMU)

##将每个图片插入到ppt中,一个文件夹中的图片占用一页ppt,fileNumber为文件夹下图片个数,folderPath为文件夹路径definsertPictures(fileNumber,folderPath):#具体函数意义,可参考https://python-pptx.readthedocs.io/en/latest/user/quickstart.html#extract-all-text-from-slides-in-presentation#以及https://python-pptx.readthedocs.io/en/latest/index.html#apiblank_slide_layout=prs.slide_layouts[8]slide=prs.slides.add_slide(blank_slide_layout)iffileNumber==1:#如果是一张图片left=top=Inches(1)#设置第一张图片的left,topheight=Inches(2)#设置每一张图片的heighteliffileNumber==2:#如果是两张图片left=top=Inches(1)#设置第一张图片的left,topheight=Inches(2)#设置每一张图片的heighteliffileNumber==3:#如果是三张图片left=top=Inches(1)#设置第一张图片的left,topheight=Inches(2)#设置每一张图片的heighteliffileNumber==4:#如果是两张图片left=top=Inches(1)#设置第一张图片的left,topheight=Inches(2)#设置每一张图片的heightfiles=os.listdir(folderPath)#得到文件夹下的所有文件名称forfileinfiles:#遍历文件夹pic=slide.shapes.add_picture(folderPath+/+file,left,top,height=height)#插入一张图片left+=Inches(1)#插入之后,将下一张图片的left增加,至于top的改变,自己可以设定#程序入口prs=Presentation()folderPath=1#第一个文件夹,其中有一张图片fileNumber=computerFileNumber(folderPath)#计算图片个数insertPictures(fileNumber,folderPath)#将每个图片插入到ppt中,一个文件夹中的图片占用一页pptfolderPath=2#第二个文件夹,其中有两张图片fileNumber=computerFileNumber(folderPath)insertPictures(fileNumber,folderPath)folderPath=3#第三个文件夹,其中有三张图片fileNumber=computerFileNumber(folderPath)insertPictures(fileNumber,folderPath)folderPath=4#第四个文件夹,其中有四张图片fileNumber=computerFileNumber(folderPath)insertPictures(fileNumber,folderPath)prs.save(test.pptx)#和prs=Presentation()对应,生成到指定pptx文件中

执行效果如下:

具体python-pptx工具中每个函数的作用,可参考:Installing-python-pptx0.6.6documentation以及python-pptx-python-pptx0.6.6documentation

参考文献:用Python制作Powerpoint演示文稿-Python-伯乐在线

python项目下载地址:使用vs2013+python2.7+python-pptx将指定文件夹下的所有图片插入到一页幻灯片中

相关阅读

  • 电脑访问网络共享提示“找不到网络路径”怎么办
  • win7 文件夹幻灯片
  • windows7下使用vs2013 7 下用VS2013 Visual Studio 2013 编译li
  • 免责声明: 凡标注转载/编译字样内容并非本站原创,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如果你觉得本文好,欢迎推荐给朋友阅读;本文链接: https://m.nndssk.com/post/42480.html。
    猜你喜欢
    最新应用
    热门应用