Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: WIN32::OLE MS WORD TABLE CELL READING PERL

by wfsp (Abbot)
on Jan 25, 2011 at 07:07 UTC ( [id://884068]=note: print w/replies, xml ) Need Help??


in reply to WIN32::OLE MS WORD TABLE CELL READING PERL

You tell us your script "does not output what I want" but don't tell us what that output was. It might have been helpful.

I would establish that it is in fact Win32::OLE that is locking up your laptop and one way to do that is write your script without it. :-)

Put your script to one side for a moment and write a short script that demonstrates that you can find the files you want to work with. You refer to a sample_folder at the top of the script (with a path relative to your script - where is your script?) and in the loop you look in parent_folder (with a full path - a better way to go). Is that correct? If it is you would need more error checking.

Perhaps something like the following would help you see what the script is actually doing (adding print statements) and then adjust if necessary.

#!/usr/bin/perl use strict; use warnings; my $directory = q{C:/Users/john/Documents/sample_folder}; opendir my $dh, $directory or die qq{cant open *$directory*}; my @dir_list = grep {/^EN-US_.+/ && -d qq{$directory/$_} } readdir $dh +; # does this print what you expect? print qq{dir_list: $directory\n}; print qq{$_\n} for @dir_list; print qq{*****\n}; for my $dir (@dir_list){ my $doc = sprintf(q{%s/%s/sample_doc.doc}, $directory, $dir); # are these the right files? print qq{$doc\n}; if (-f $doc){ print qq{found\n}; } else{ print qq{not found\n}; } }
When you're sure you can see the files you need then perhaps another short script using Win32::OLE to open one of the files and get at the table cells.

Get both working nicely and then put them together.

Replies are listed 'Best First'.
Re^2: WIN32::OLE MS WORD TABLE CELL READING PERL
by Anonymous Monk on Jan 26, 2011 at 23:14 UTC

    Thanks for your kind reply. I learned a lot from your script and actually did not know what qq means, now I know.

    Btw, What does sprintf(q{%s/%s...}) mean?

    Nevertheless, I had tried a similar approach before my original post to see whether I can open the word file at all and it was working because I could see the files open. But thanks for the new knowledge. Any more help is appreciated.

    as for the output you asked I simply get an empty zero-length string.

      any news on htis

        No, none were expected

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://884068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found