Joh*_*ohn 2 powershell scripting special-characters powershell-2.0
我正在尝试使用PowerShell,并使其将版权字符输出到Microsoft Word文档中。例如,下面列出的代码是我要使用的代码,它不起作用。
$SummaryPara.Range.Text = "© "
$SummaryPara.Range.Text = "Get-Date -Format yyyy"
$SummaryPara.Range.Text = " - Name of Org Here "
$SummaryPara.Range.InsertParagraphAfter()
Run Code Online (Sandbox Code Playgroud)
我需要以某种方式使用Alt+ 0169序列吗?
我不确定我在做什么错,因为以下代码似乎有效:
$selection.TypeParagraph()
$selection.TypeText("© ")
$selection.TypeText((Get-Date -Format yyyy))
$selection.TypeText(" - Name of Org Here ")
$selection.TypeParagraph()
Run Code Online (Sandbox Code Playgroud)
我如何才能同时使用版权字符和其他类似的特殊字符?
这里有一些问题。我将列出这些地址并分别处理:
您可以通过将Unicode表示形式转换为来获取所需的任何字符char
。在这种情况下
[char]0x00A9
Run Code Online (Sandbox Code Playgroud)您将新值分配给$SummaryPara.Range.Text
三倍。因此,您每次都覆盖先前的值,而不是连接('+'运算符),我认为这是您要尝试执行的操作。
您正在尝试使用cmdlet Get-Date,但是由于已对其进行了引用,因此最终将得到文本字符串“ Get-Date -Format yyyy”,而不是cmdlet的结果。
综上所述,我认为您想要这样的东西:
$word = New-Object -ComObject Word.Application
$doc = $word.Documents.Add()
$SummaryPara = $doc.Content.Paragraphs.Add()
$SummaryPara.Range.Text = [char]0x00A9 + ($date = Get-Date -Format yyyy) + " - Name of Org Here "
$word.Visible = $true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4351 次 |
最近记录: |