Read MS Word table data row wise using win32:ole perl -
I am new to Perl to Win32: Oll module at the command prompt, I am trying to print MS Word table data row I am But I'm able to print the last line of the table. Can you help me solve this problem? thank you in advanced.
Below is my code:
#! Use / usr / bin / perl strict; Use warnings; File :: spec :: functions use qw (catfile); Use Win32 :: OLE qw (in); Use Win32 :: OLE :: Conte 'Microsoft Word'; $ Win32 :: OLE :: Alert = 3; My $ word = get_word (); $ Word- & gt; {DisplayAlerts} = wdAlertsNone; $ Word- & gt; {Visible} = 1; My $ Doctor = $ word- & gt; {Document} - & gt; Open ('C: \\ PerlScripts \\ myTest.docx'); My $ tables = $ word- & gt; Active document- & gt; {'Tables'}; For my $ table (in $ tables) {my $ tableText = $ table- & gt; ConvertText ({separator = & gt; wdSeparateByTabs}); Print "table:" $ TableText-> Text (). "\ N"; } $ Doc- & gt; Close (0); Sub get_word {my $ word; Eval {$ word = Win32 :: OLE- & gt; GetActiveObject ('Word.Application');}; Die "$ @ \ n" if $ @; Unless (defined $ word) {$ word = win32 :: OLE- & gt; New ('Word.Application', sub {$ _ [0] - & gt; quit}) or die "Oh, can not start Word:", Win32 :: OLE- & gt; Last errer, "\ n"; } Return word; }
The perfect solution by any means, but is an improvement on this issue . / P>
I use a string separator "\ n \ n" which produces the following output ...
After this, the need is: Hacking (
C: \ StackOverflow & gt; Pearl word.pl meTest.docx table: Headerl Header2 Header3 Header4 ROWl-CELLl ROWl-CELL2 ROWl-CELL3 ROWl-Cell4 ROW2-CELLl ROW2-CELL2 ROW2-CELL3 ROW2-Cell4 ROW2- Cell5 . here is the code I have table loop that I have some other code commented out used to hack on the data $ tableRange- & gt ,. {text} comment Delete For Further Experiment
# / Usr / bin / perl use strict; use warnings; use File :: Spec :: Functions qw (catfile), Win32 :: OLE qw) in ( Use Win32: :: OLE :: CONST 'Microsoft Word'; $ Win32 :: OLE :: Warning = 3, my $ word = get_word (); $ word-> {DisplayAlerts} = wdAlertsNone; $ word- & gt; {city} = 1; my $ doc = $ word- & gt; {document} - & gt; Open ( "Mitst Daokks'); my $ tables = $ wo rd- & gt; ActiveDocument-> {'Table'}; For my $ table (in $ tables) {my $ tableRange = $ table- & gt; Convertto Text ({separator = & gt; "\ n \ n"}); Print "Table: \ n". $ TableRange-> {Text}. "\ N"; # Foreign currency $ word (partition / \ n /, $ tableRange- & gt; {text}) {# print $ word "\ N"; # # $ Userinput = & lt; STDIN & gt; #}} $ Doc- & gt; Close (0); Sub get_word {my $ word; Eval {$ word = Win32 :: OLE- & gt; GetActiveObject ('Word.Application');}; Die "$ @ \ n" if $ @; Unless (defined $ word) {$ word = Win32 :: OLE- & gt; New ('Word.Application', sub {$ _ [0] - & gt; quit}) or die "Oh, can not start Word:", Win32 :: OLE- & gt; Last errer, "\ n"; } Return word; } Sorry, I can not help more
Comments
Post a Comment