How do i make a value retrieved from a Microsoft word document a string in Powershell? -
i have powershell script read value table in microsoft word document. when try write value text file used later batch file, not work desired. text file displays value dot on end. when read value text file in batch file messed up.
$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)
the character seeing in .txt file bell character. can use regex operator strip out this:
$content -replace "\a","" > 'c:\filename.txt' update: shows how remove characters not in range, not single character. in example, not number character replaced null character:
$content -replace "[^0-9]","" > 'c:\filename.txt'
Comments
Post a Comment