Reputation: 5395
I have to write a powershell script that can parse word document. Specifically, it has to read text from textboxes and store it in a variable. I know how to read text e.g. from a paragraph, but I don't know how to deal with textboxes. I would appreciate a sample.
Here is a part of my code:
$Word = New-Object -comobject Word.Application
$Word.Visible = $False
$datasheet = $word.Documents.Open($files[$i].FullName)
$value = ....?
Here is a screenshot of the box I need to read from:
Upvotes: 0
Views: 1289
Reputation: 174900
Enumerate the contents of the Shapes
collection and filter for shapes of the msoTextBox
type (17):
$datasheet.Shapes |Where-Object {$_.Type -eq 17} |ForEach-Object {
# copy $_.TextFrame.TextRange.Text to wherever you need it in here
# $_.TextFrame.TextRange is a range object like any other (useful if you need formatting details or raw XML for example)
}
Upvotes: 3