之前打算用python-pptx,但是好像只能处理pptx文件。于是查了一下,有用VBA的,但是我嫌太麻烦了,还是直接用powershell方便。
# 【功能】搜索当前目录及子目录下的所有Powerpoint(.ppt .pptx)文件并导出其中包含的文字内容
# 【使用方法】首先关闭电脑上所有正在运行的PPT程序。把本文件复制到PPT文件所在的文件夹,然后打开powershell,输入
# .\ppt2txt.ps1 >"content.txt"
# 然后等着就好啦,导出的文字内容在content.txt里面
# 【常见问题】如果无法运行脚本,需要用管理员权限打开powershell并运行Set-ExecutionPolicy UnRestricted,并选择Y
Add-type -AssemblyName office
Add-type -AssemblyName microsoft.office.interop.powerpoint
# 搜索当前目录及子目录下的所有PPT文件
$pptSlides = Get-Childitem -Include *.ppt, *.pptx -Recurse # -Path $path
# 创建一个PPT进程
$program = New-Object -ComObject PowerPoint.Application
#$ppt.Activate()
# possibly many PowerPoint files in the folder so to stop PowerPoint app from appearing and disappearing
$program.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
# walk through the collection of slides
foreach ($ppt in $pptSlides) {
# write-host $ppt
$presentation =