I'm new to powershell and achieving this has caused me a great headache!
I'm attempting to create a program that opens a .docx file from a path and parses through a file that contains tables in the middle of other paragraphs and text. I would like to access specific information to be filled into external table column in a Microsoft Program. Attached is a screenshot of the tables:
that have the information I would like to grab. The Event Date is the one I'm most interested in grabbing.
Asked
Active
Viewed 1,544 times
-6

Mathias R. Jessen
- 157,619
- 12
- 148
- 206

Jay
- 1
- 1
-
3What have you tried so far. What specific problem are you having? – EBGreen Jul 18 '18 at 17:22
-
The main problem is extracting specific data from tables. I've got the .docx file to open and my program can read all the contents but I've failed to parse through the tables for the data I'm looking for. – Jay Jul 18 '18 at 17:27
-
3Well then maybe start by posting some code in the question. – Paxz Jul 18 '18 at 17:30
-
1Yes, I should have been more specific. What code have you tried? What specific problems are you having with the code that you have written? – EBGreen Jul 18 '18 at 17:32
1 Answers
2
This could be a duplicate to the approaches discussed in this answered thread.
Read word document (*.doc) content with tables etc
You can enumerate the tables in a Word document via the Tables collection. The Rows and Columns properties will allow you to determine the number of rows/columns in a given table. Individual cells can be accessed via the Cell object.
Example that will print the value of the cell in the last row and last column of each table in the document:
$wd = New-Object -ComObject Word.Application
$wd.Visible = $true
$doc = $wd.Documents.Open($filename)
$doc.Tables | ForEach-Object {
$_.Cell($_.Rows.Count, $_.Columns.Count).Range.Text
}

postanote
- 15,138
- 2
- 14
- 25