【发布时间】:2014-11-05 15:47:02
【问题描述】:
我正在尝试打开一个现有的 word 文件并向其中添加一个新页面。这个新页面会有一些内容,我总是希望这个页面位于第 2 位。因此,第一页将始终相同,并且添加的每个新内容都应该转到第二页。到目前为止,我的代码如下:
$day = get-date -Format "dd-MMM-yyyy"
$filedate = Get-Date -Format "dd/MMM/yy - H tt"
$word = New-Object -ComObject word.application
$word.visible = $false
$doc = $word.documents.open("$home\desktop\Network Report.docx")
$selection = $word.selection
$Selection.InsertNewPage() #So, this page should be added at number 2
$selection.Font.Size = 14
$selection.Font.color ="wdColorBlack"
$selection.TypeText("Network Report for $filedate")
$selection.TypeParagraph()
$selectimage = $selection.InlineShapes.AddPicture("$home\desktop\screenshot.jpeg")
$selection.TypeParagraph()
$Section = $Doc.Sections.Item(1);
$Header = $Section.Headers.Item(1);
$Footer = $Section.Footers.Item(1);
$Header.Range.Text = "$campus Network Report - $day "
$doc.save()
经过不同的表格后,我尝试了不同的以下内容:
$gotoPage1 = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage
$gotoNext1 = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute
$gotoCount1 = null
$gotoName1 = 1
$Selection.GoTo([ref]$gotoPage1, [ref]$gotoNext1, [ref]$gotoCount1, [ref]$gotoName1)
但我没有运气。如何添加新页面作为第二页?
【问题讨论】:
标签: powershell ms-word