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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |