Извлечь заметки докладчика
Собирает заметки со всех слайдов в Markdown, текст или CSV через PowerPoint COM.
Что делает скрипт
Скрипт открывает презентацию только для чтения и берёт текст с NotesPage каждого слайда. Формат результата определяется расширением файла: MD, TXT или CSV. Заголовки слайдов помогают быстро найти нужную заметку.
- Нужен установленный PowerPoint. Файл открывается только для чтения.
Быстрый старт
powershell -File Export-PptxNotes.ps1 -Path .\demo.pptx
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Export-PptxNotes.ps1 -Path .\demo.pptx -OutFile notes.mdpowershell -File Export-PptxNotes.ps1 -Path .\talk.pptx -OutFile notes.csv -Force
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
Export-PptxNotes.ps1
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[string]$OutFile,
[switch]$Force
)
$ErrorActionPreference = 'Stop'
$resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path
$extension = [IO.Path]::GetExtension($resolved).ToLowerInvariant()
if ($extension -notin @('.pptx', '.pptm', '.ppt')) {
throw 'Поддерживаются файлы .pptx, .pptm и .ppt'
}
if (-not $OutFile) {
$outDir = Join-Path (Get-Location) 'notes'
$OutFile = Join-Path $outDir ([IO.Path]::GetFileNameWithoutExtension($resolved) + '_notes.md')
}
$target = [IO.Path]::GetFullPath($OutFile)
$format = [IO.Path]::GetExtension($target).ToLowerInvariant()
if ($format -notin @('.md', '.txt', '.csv')) {
throw 'Укажите расширение .md, .txt или .csv для OutFile'
}
if ((Test-Path -LiteralPath $target) -and -not $Force) {
throw "Файл уже существует: $target. Добавьте -Force."
}
$parent = [IO.Path]::GetDirectoryName($target)
if ($parent -and -not (Test-Path -LiteralPath $parent)) {
New-Item -ItemType Directory -Path $parent -Force | Out-Null
}
$powerPoint = $null
$presentation = $null
try {
try {
$powerPoint = New-Object -ComObject PowerPoint.Application
} catch {
throw 'PowerPoint не найден. Установите настольный Microsoft PowerPoint.'
}
$presentation = $powerPoint.Presentations.Open($resolved, $true, $false, $false)
$rows = foreach ($slide in $presentation.Slides) {
$title = ''
try {
if ($slide.Shapes.Title) {
$title = [string]$slide.Shapes.Title.TextFrame.TextRange.Text
}
} catch {
$title = ''
}
$texts = New-Object System.Collections.Generic.List[string]
foreach ($shape in $slide.NotesPage.Shapes) {
try {
if ($shape.HasTextFrame -eq -1 -and $shape.TextFrame.HasText -eq -1) {
$value = [string]$shape.TextFrame.TextRange.Text
if ($value.Trim()) {
$texts.Add($value.Trim())
}
}
} catch {
continue
}
}
[pscustomobject]@{
Slide = $slide.SlideIndex
Title = ($title -replace '\s+', ' ').Trim()
Notes = ($texts -join [Environment]::NewLine).Trim()
}
}
if ($format -eq '.csv') {
$rows | Export-Csv -LiteralPath $target -NoTypeInformation -Encoding UTF8
} else {
$lines = New-Object System.Collections.Generic.List[string]
if ($format -eq '.md') {
$lines.Add("# Заметки: $([IO.Path]::GetFileName($resolved))")
} else {
$lines.Add("Заметки: $([IO.Path]::GetFileName($resolved))")
}
foreach ($row in $rows) {
$lines.Add('')
if ($format -eq '.md') {
$lines.Add("## Слайд $($row.Slide): $($row.Title)")
} else {
$lines.Add("=== Слайд $($row.Slide): $($row.Title) ===")
}
$lines.Add('')
if ($row.Notes) {
foreach ($line in ($row.Notes -split "`r?`n")) {
$lines.Add($line)
}
} else {
$lines.Add('Заметок нет.')
}
}
Set-Content -LiteralPath $target -Value $lines -Encoding UTF8
}
Write-Host "Готово: $target"
} finally {
if ($presentation) {
$presentation.Close()
}
if ($powerPoint) {
$powerPoint.Quit()
}
if ($presentation) {
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($presentation)
}
if ($powerPoint) {
[void][Runtime.InteropServices.Marshal]::ReleaseComObject($powerPoint)
}
[GC]::Collect()
}
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.