in reply to Re^2: Reading tables in MS Word
in thread Reading tables in MS Word
For general maintainability, I recommend avoiding $word->ActiveDocument. If you'll only be working with the current document, then do my $doc = $word->ActiveDocument somewhere at the top of your code.
Going from this Stackoverflow answer, you could use $doc->Selection->GoTo as suggested in the Microsoft documentation:
for my $para (1..$doc->Paragraphs->Count) { $doc->Selection->GoTo( What => wdGoToParagraph, Which => wdGoToAbs +olute, Count => $i ); my $para = $doc->Selection->Paragraphs->[0]; $doc->Selection->GoTo( What => wdGoToTable, Which => wdGoToNext ); my $table = $doc->Selection->Tables->[0]; ... }
This will still trip for paragraphs that have no table. Maybe in that case, it makes sense to step through all tables instead and then go backwards to find the corresponding paragraph or heading, depending on how your document is structured.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reading tables in MS Word
by spiral (Novice) on Jul 15, 2025 at 14:09 UTC | |
by Corion (Patriarch) on Jul 16, 2025 at 06:08 UTC | |
by spiral (Novice) on Jul 16, 2025 at 15:20 UTC | |
by Corion (Patriarch) on Jul 16, 2025 at 15:29 UTC | |
by spiral (Novice) on Jul 16, 2025 at 21:11 UTC | |
|