PowerPoint의 총 페이지 수를 PowerShell로 업데이트 (이슈 남음)
10200 단어 파워 포인트PowerShell
소개
당사의 PowerPoint 형식에는 총 페이지 수의 항목이 있지만,
여기가 업데이트되지 않았을 뿐이라도 자료가 통과되지 않는 것이 여러 번있었습니다.
(내용을 봐줘…)
특히 <#>/000
라는 텍스트 상자가 슬라이드 마스터로 설정됩니다.
여기의 000을 총 페이지수로 수동으로 갱신할 필요가 있습니다만, 수고입니다.
꽉 업데이 트와 함께 짜기 시작했지만 걸려 있습니다.
참고 자료
PowerPoint VBA 참조
전회의 Excel과 달리 묘하게 확실히 오지 않는 것이 산견된다.
환경
PowerPoint VBA 참조
전회의 Excel과 달리 묘하게 확실히 오지 않는 것이 산견된다.
환경
소스 코드
PageCount.ps1#PowershellでPowerPointの総ページ数を更新
#未解決問題2点あり
#ダイアログを使えるようにする
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$dialog = New-Object System.Windows.Forms.OpenFileDialog
$dialog.Filter = "pptファイル(*.ppt;*.pptx)|*.PPT;*.PPTX"
$dialog.InitialDirectory = "C:\Users\1501275\Desktop\kojin"
$dialog.Title = "ファイルを選択"
if($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){
$filepath = $dialog.FileName
#なにかと便利なのでつい用意してしまう
$folder = Split-Path -parent $filepath
$filename = [System.IO.Path]::GetFileNameWithoutExtension($filepath)
$extension =[System.IO.Path]::GetExtension($filepath)
} else {
Read-Host "キャンセルされました。ENTERキーを押してください。"
return
}
#PowerPoint側の作業
$pp = New-Object -ComObject PowerPoint.Application
$pp.Visible = "msoTrue" #可視化
$pp.DisplayAlerts = "ppAlertsAll" #アラート類も可視化
$slide = $pp.presentations.Open($filepath)
#変数定義
$variable = "‹#›"
$pagecount = $slide.Slides.Count
#実行部分
foreach ($shape in $slide.slidemaster.shapes){ #スライドマスター内の各オブジェクトについて
if($shape.HasTextFrame){ #そのオブジェクトがテキストを持っていれば
$text = $shape.TextFrame2.TextRange.Text #テキストの内容を取得し
$pos_variable = $text.indexof($variable) #テキスト内のvariableの位置を取得し
if($pos_variable -ge 0){ #variableが存在すれば対象の図形と判断し
$shape.TextFrame2.textrange.replace("000",$pagecount)
}
}
}
$pp.ActivePresentation.SaveAs($folder + "\" + $filename +"_更新" +$extension)
#末端処理
$slide.Close()
$pp.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($pp)
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($slide)
출력
Before
After
했어.
그리고 왠지 슬라이드는 닫을 수 있지만 PowerPoint 자체를 종료할 수 없다.
현재 조사 중입니다.
Reference
이 문제에 관하여(PowerPoint의 총 페이지 수를 PowerShell로 업데이트 (이슈 남음)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/takaaki3110/items/824241483bc11a3d46cf
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#PowershellでPowerPointの総ページ数を更新
#未解決問題2点あり
#ダイアログを使えるようにする
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$dialog = New-Object System.Windows.Forms.OpenFileDialog
$dialog.Filter = "pptファイル(*.ppt;*.pptx)|*.PPT;*.PPTX"
$dialog.InitialDirectory = "C:\Users\1501275\Desktop\kojin"
$dialog.Title = "ファイルを選択"
if($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){
$filepath = $dialog.FileName
#なにかと便利なのでつい用意してしまう
$folder = Split-Path -parent $filepath
$filename = [System.IO.Path]::GetFileNameWithoutExtension($filepath)
$extension =[System.IO.Path]::GetExtension($filepath)
} else {
Read-Host "キャンセルされました。ENTERキーを押してください。"
return
}
#PowerPoint側の作業
$pp = New-Object -ComObject PowerPoint.Application
$pp.Visible = "msoTrue" #可視化
$pp.DisplayAlerts = "ppAlertsAll" #アラート類も可視化
$slide = $pp.presentations.Open($filepath)
#変数定義
$variable = "‹#›"
$pagecount = $slide.Slides.Count
#実行部分
foreach ($shape in $slide.slidemaster.shapes){ #スライドマスター内の各オブジェクトについて
if($shape.HasTextFrame){ #そのオブジェクトがテキストを持っていれば
$text = $shape.TextFrame2.TextRange.Text #テキストの内容を取得し
$pos_variable = $text.indexof($variable) #テキスト内のvariableの位置を取得し
if($pos_variable -ge 0){ #variableが存在すれば対象の図形と判断し
$shape.TextFrame2.textrange.replace("000",$pagecount)
}
}
}
$pp.ActivePresentation.SaveAs($folder + "\" + $filename +"_更新" +$extension)
#末端処理
$slide.Close()
$pp.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($pp)
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($slide)
Before
After
했어.
그리고 왠지 슬라이드는 닫을 수 있지만 PowerPoint 자체를 종료할 수 없다.
현재 조사 중입니다.
Reference
이 문제에 관하여(PowerPoint의 총 페이지 수를 PowerShell로 업데이트 (이슈 남음)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/takaaki3110/items/824241483bc11a3d46cf텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)