首页 > 解决方案 > Microsoft Word power shell 脚本跳过所有已删除的修订行/段落

问题描述

我正在尝试阅读 word 文档并从特定段落或句子中获取数字。但是有些句子被删除了,并且正在修订轨道上。所以我的输出仍然包含带有预期数字的已删除句子。基本上我不想在输出中包含已删除的句子。我也无法通过接受所有修订来保存文件。

我的代码如下所示。

$file2 = "C:\work\Powershell\Scenarios\ALPtest Life AnnualV12.docx"

$word = New-Object -ComObject Word.Application
$document = $word.documents.open($file2,$false,$true)


if ($document.Content.Find.Execute('Document Conditions'))
{
    Write-Host $WantFile "contains 'Document Conditions'" `n
    $Paras = $Document.Paragraphs 
                  
    foreach($para in $paras)
    {
        $Text= $para.Range.Text

        if ($text.Trim() -eq 'Document Conditions')
        {
            Write-Host "Hurahhhhhhh"
            $start=1

        }
        elseif ( $start -eq 1 -and ($text -match "[0-9]"))
        {
            if ($text.Revsision -ne "wdRevisionDelete")
            {
                Write-Host "Found revision del : $text"
            }
        }
    }
}

非常感谢您帮助对此进行排序。

标签: powershell

解决方案


推荐阅读