PowerPoint 幻灯片计数

PowerPoint 幻灯片计数

如何获取多个 PowerPoint 演示文稿的幻灯片总数?我有一个包含约 20 个 PowerPoint 文件的文件夹,我很想知道合并的幻灯片数量。

我知道您可以右键单击并检查文件信息以获取该文件信息,但如果我选择多个文件,它只会显示“(多个值)”(这很愚蠢,因为选择多个媒体文件会给您它们的总长度)。

我谷歌了一下,但找不到任何相关信息。有没有简单的方法可以做到这一点?或者某种已知的脚本?

谢谢!

答案1

Michael Halpin 有一个 Powershell 脚本可以实现这一点。原始网站已不存在,但存档于https://web.archive.org/web/20180204011318/http://michaelhalpin.azurewebsites.net:80/use-powershell-to-get-numbers-of-slides-in-powerpoints/

脚本如下:

[CmdletBinding()]
[Alias()]
[OutputType([psobject])]
Param(
# The folder containing the files to count
[Parameter(ValueFromPipelineByPropertyName=$true,
        Position=0)]
$Path = 'C:\temp'
)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Office
Add-Type -AssemblyName Microsoft.Office.Interop.Powerpoint

Write-Verbose "Getting files from $path"
$files  = Get-ChildItem -filter *.ppt* -Path $Path

[psobject]$NumberOfSlides= @()

Foreach ($file in $files){
    $application = New-Object -ComObject powerpoint.application
    Write-Verbose "Opening $file" 
    $presentation = $application.Presentations.open($file.fullname)

    $slideCount =  New-Object System.Object
    $slideCount | Add-Member -type NoteProperty -name Name -value $file.name
    $slideCount | Add-Member -type NoteProperty -name Slides -value $presentation.Slides.Count

    #Introduce a slight wait so powerpnt.exe has time to process file
    Start-Sleep -Seconds 2
    $presentation.Close()

    $NumberOfSlides += $slideCount
    }

$NumberOfSlides

Write-Verbose "Cleaning up processes"
get-process powerpnt | Stop-Process

相关内容