Extract text from MS Word table without bullets [Powershell 4.0]

I want to extract some text from the word ms from a specific table: table and text

However, when I execute the code:

$objWord = New-Object -ComObject Word.Application
$objWord.Visible = $true
$filename = 'D:\test.docx'
$objDocument = $objWord.Documents.Open($filename)
$LETable = $objDocument.Tables.Item(1)
$LETableCols = $LETable.Columns.Count
$LETableRows = $LETable.Rows.Count

Write-output "Starting to write... "

$content2 = $LETable.Cell(6,2).Range.Text
$content3 = $LETable.Cell(7,1).Range.Text
$content4 = $LETable.Cell(7,2).Range.Text
#Write-host $content2
$doc2 = $objWord.Documents.Add()
$objWord.Selection.typetext("$content2")
$objWord.Selection.typetext("$content3")
$objWord.Selection.typetext("$content4")
#$objDocument.Close()
#$objWord.Quit()
# Stop Winword Process
#$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objWord)

bullets - question marks

How to remove these bullet question marks? I want just text.

+4
source share
2 answers

You will need to find an unicode expression for this character. After that, using a regular expression can be useful to replace it with a blank character, space or tab. I even try to use a "direct" copy and paste "✀", and it also works.

To remove a character: $ String -replace '✀'

to replace it:

 $String = "Just ✀ and another ✀"
#replace ✀ with cat
 $String -replace '✀','cat'

Ant result:

Just cat and another cat
+1
source

. Open-Xml-PowerTools.

docx xml, .

0

Source: https://habr.com/ru/post/1651507/


All Articles