I have been looking at this problem for sometime now. I want to be able to go through bunch of documents and extract some info from MS Word table and output to an HTML file.

Right now, I don't care about the actual extracted cell being outputted to HTML, rather I just want to print to cmd prompt. The problem is it hangs my cmd prompt window when I run it (used to be worse - it kept beeping until I had to take the laptop battery out) and does not output what I want. How do I read the cell and output to cmd correctly?

use warnings; use strict; # we are going be working with MS Word Objects use Win32::OLE qw(in with); # some sites advise me to use these but I am not sure # why we need them and can't really understand # win32::OLE. If there is a way to decipher them I am happy # to know # use Win32::OLE::Const 'Microsoft Word'; # use Win32::OLE::Enum; use CGI; # we'll be having some HTML writing my $text = ""; my $directory = "../sample_folder"; opendir (DH, $directory) || die "can't opendir $directory: $!"; # test whether the item returned by grep is a file and its name does n +ot start with "_" # because there is one redirect input which start with "_" my @dir_list = grep { (/^EN-US_.+/) && -d "$directory/$_" } readdir(DH +); # we are working with Word application my $Word = Win32::OLE->new('Word.Application', 'Quit'); my $root = "C:\\Documents and Settings\\parent_folder"; foreach (@dir_list){ # extract the language abbreviation m/^EN-US_(.+)$/i; my $doc = "$root\\EN-US_$1\\sample_doc.doc"; $Word->Documents->Open("$doc") || die("Unable to open $doc ", Win3 +2::OLE->LastError()); $Word->{Visible}= 0; # we don't need to see Word in an active wind +ow # get the first table my $table = $Word->ActiveDocument->Tables(1); # $table -> Select(); # do I need to select? $text = $table->Cell(1,1)->Range->{Text}; print "*$text*"; #my $language = lc($1); # Prepare OUT_FOOTER file #open(OUT_FOOTER, "> $directory/updates/footer_$language.html") || + die("can't open $directory/updates/footer_$language.html for writing +: $!"); # close document and Word instance print "Closing document and Word\n"; $Word->ActiveDocument->Close(); close OUT_FOOTER; } $Word->Quit; closedir DH;

In reply to WIN32::OLE MS WORD TABLE CELL READING PERL by pooTan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.