我有一个 powershell 脚本,它将从 Microsoft Word 文档中的表中读取一个值。但是,当我尝试将该值写入文本文件以供批处理文件稍后使用时,它无法按预期工作。文本文件在末尾显示带有点的值。然后,当我从批处理文件中的文本文件中读取值时,一切都搞砸了。
$wd = New-Object -ComObject Word.Application
$wd.Visible = $true
$doc = $wd.Documents.Open("C:\Users\jxh\Desktop\taskids.doc" )
$iTable = $doc.Tables.Item(1)
$r = $iTable.Rows.Count
$c = 1
Write-host $r "x" $c
$content = $iTable.Cell($r, $c).Range.Text
Write-host $content
if ($content) {
$r = $iTable.Rows.Count - 1
$c = 1
Write-host $r "x" $c
$content = $iTable.Cell($r, $c).Range.Text #| Out-File C:\filename.txt
Write-host $content
$iTable.Cell($iTable.Rows.Count, $c).Range.Text=$content+1 }
$content > C:\filename.txt
$doc.Close()
$wd.Quit()
# Stop Winword Process
$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($wd)