List Info

Thread: Hot to read the contents of an MS Word document




Hot to read the contents of an MS Word document
user name
2006-05-30 16:28:24
I'm stuck on how to read a MS Word document. Using Windows XP, latest ActiveState Perl 5.5.x.
 
I know how to create a MS Word document, and I found some decent examples on the internet as well.
 
May I please have an example of how to read an MS Word document?
 
Here is one example I found on the internet, that did NOT work:
 
use Win32::OLE;
use Win32::OLE::Enum;
$document = Win32::OLE -> GetObject("srdd.doc");
open (FH,">$ARGV[0]");
print "Extracting Text ...\n";
$paragraphs = $document->Paragraphs(); ;  # This errors out !!!
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next())) {
    $style = $paragraph->{Style}->{NameLocal};
    print FH "+$style\n";
    $text = $paragraph->{Range}->{Text};
    $text =~ s/[\n\r]//g;
    $text =~ s/\x0b/\n/g;
    print FH "=$text\n";
}
 
Returns the error message:
 
Can't call method "Paragraphs" on an undefined value at fi.pl line 9.
 
 
Thanks
  --cg

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Hot to read the contents of an MS Word document
user name
2006-05-31 09:30:04
Здравствуйте C.A.,

Tuesday, May 30, 2006, 7:28:24 PM, Вы написали:


CAG>   use Win32::OLE;
CAG> use Win32::OLE::Enum;
CAG>   $document = Win32::OLE ->
GetObject("srdd.doc");
       You may try point the full path of file and replace
double
       quotes with singles.
open (FH,">>$ARGV[0]");
CAG>   print "Extracting Text ...\n";
CAG>   $paragraphs = $document->Paragraphs();   # This
errors out !!!
CAG>   $enumerate = new Win32::OLE::Enum($paragraphs);
CAG>   while(defined($paragraph = $enumerate->Next()))
{
CAG>       $style =
$paragraph->->;
CAG>       print FH "+$style\n";
CAG>       $text = $paragraph->->;
CAG>     $text =~ s/[\n\r]//g;
CAG>     $text =~ s/\x0b/\n/g;
CAG>       print FH "=$text\n";
CAG>   }

   



-- 
С уважением,
 Сергей                            mailto:crowpfu.ic.kharkov.ua


_______________________________________________
Perl-Win32-Database mailing list
Perl-Win32-Databaselistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )