我有一個簡單的腳本,可以為參加考試的員工創建 Word 檔案和 PowerPoint 檔案,其中所需的檔案已預加載到檔案共享上的用戶區域。Word 檔案打開并使用代碼行創建檔案標題
$Header = $Section.Headers.Item(1);
$Header.Range.Text = "$FirstName $SecondName $ID Activity 1";
PowerPoint 更有趣一點,當您添加標題時,它會詢問日期。有沒有辦法用powershell做到這一點?我們在之后列印它們,因此將 CSV 中的變數列印在檔案標題中會更有好處。
如果這不可行,有沒有辦法編輯第一張幻燈片以在 PowerPoint 的第一張幻燈片中包含變數。
如果有人能夠查看代碼或任何簡化它的方法,那將是非常受歡迎的
下面列出了 CSV,完整的腳本在底部 :)
ID Four First Second
219999 9999 Tech Support
祝你有美好的一天
$Exams = Import-Csv "C:\\techtest.csv"
$fileserver = "C:\\ExamHomes\"
foreach ($User in $Exams)
{
$FirstName = $User.First
$SecondName = $User.Second
$ID = $User.ID
$FourID = $User.Four
$Time = "am"
$Date = "1511"
$Word = New-Object -ComObject Word.Application;
$Word.Visible = $false;
$Doc = $Word.Documents.Add();
$Section = $Doc.Sections.Item(1);
$Header = $Section.Headers.Item(1);
$Header.Range.Text = "$FirstName $SecondName $ID Activity 1";
$Doc.SaveAs("$fileserver\${date}${time}-${FourID}\Desktop\activity 1_${ID}_${FirstName}_${SecondName}.docx");
$Word.Quit()
Write-Host "File 'activity 1_${ID}_${FirstName}_${SecondName}.docx' for $FirstName $SecondName has been created and sent to the folder ${date}${time}-${FourID}" -BackgroundColor Black -ForegroundColor Cyan
add-type -assembly microsoft.office.interop.powerpoint
$Application = New-Object -ComObject powerpoint.application
$slideType = "microsoft.office.interop.powerpoint.ppSlideLayout" -as [type]
$presentation = $application.Presentations.add()
$presentation.SaveAs("$fileserver\${date}${time}-${FourID}\Desktop\activity 1_${ID}_${FirstName}_${SecondName}.pptx")
$presentation.close()
Stop-Process -name POWERPNT -Force
Write-Host "File 'activity 1_${ID}_${FirstName}_${SecondName}.pptx' for $FirstName $SecondName has been created and sent to the folder ${date}${time}-${FourID}" -BackgroundColor Black -ForegroundColor Cyan
}
Write-Host "All Staff have successfully had their document deployed for the exam" -BackgroundColor Black -ForegroundColor Red
uj5u.com熱心網友回復:
頁眉僅適用于Notes Master 和講義母版物件, 但您可以在幻燈片上添加頁腳。
Add-Type -AssemblyName microsoft.office.interop.powerpoint
$Application = New-Object -ComObject powerpoint.application
$presentation = $application.Presentations.add()
$slide = $presentation.Slides.Add(1, [Microsoft.Office.Interop.PowerPoint.PpSlideLayout]::ppLayoutTitle)
$slide.Shapes.Title.TextFrame.TextRange.Text = "My Title"
$slide.Shapes(2).TextFrame.TextRange.Text = "My SubTitle"
$slide.HeadersFooters.Footer.Visible = $true
$slide.HeadersFooters.Footer.Text = "My Name"
您可以DateAndTime HeaderFooter像這樣在物件上使用一些文本:
$slide.HeadersFooters.DateAndTime.Visible = $true
$slide.HeadersFooters.DateAndTime.UseFormat = $true
$slide.HeadersFooters.DateAndTime.Format = [Microsoft.Office.Interop.PowerPoint.PpDateTimeFormat]::ppDateTimeFigureOut
$slide.HeadersFooters.DateAndTime.Text = "Coucou"
編輯:SLIDE MASTER 事實上,這可以在 上定義,SlideMaster以便每個都Slide繼承頁腳、頁碼或日期時間的值。這是在表示級別定義的。因此,取決于您想要什么,在您創建的SlideMaster或任何Slide您創建的物件上執行此操作。可能 aSlide可能會覆寫SlideMaster.
$presentation.SlideMaster.HeadersFooters.SlideNumber.Visible = $true
$presentation.SlideMaster.HeadersFooters.Footer.Visible = $true
$presentation.SlideMaster.HeadersFooters.Footer.Text = "My Name"
$presentation.SlideMaster.HeadersFooters.DateAndTime.Visible = $true
$presentation.SlideMaster.HeadersFooters.DateAndTime.UseFormat = $true
$presentation.SlideMaster.HeadersFooters.DateAndTime.Format = [Microsoft.Office.Interop.PowerPoint.PpDateTimeFormat]::ppDateTimeFigureOut
$presentation.SlideMaster.HeadersFooters.DateAndTime.Text = "Something"
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/331884.html
標籤:电源外壳
