Connecting Tech Pros Worldwide Forums | Help | Site Map

Parsing a Word File ?

Needs Regular Fix
 
Join Date: Dec 2006
Posts: 293
#1: Oct 2 '08
How to parse a Word File to retrieve the contents ?

Icecrack's Avatar
Expert
 
Join Date: Sep 2008
Location: Sydney, Australia
Posts: 173
#2: Oct 2 '08

re: Parsing a Word File ?


have you tried this yourself ?
if you have post some code


and is this microsoft word or is this just a text file?
nithinpes's Avatar
Expert
 
Join Date: Dec 2007
Posts: 400
#3: Oct 3 '08

re: Parsing a Word File ?


For parsing MS word file, you can make use of Win32::OLE.
Needs Regular Fix
 
Join Date: Dec 2006
Posts: 293
#4: Oct 6 '08

re: Parsing a Word File ?


When I run the below program the MS Word Program also opens. How to avoid that ?



Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. use Win32::OLE;
  4. use Win32::OLE::Enum;
  5.  
  6. parseAndScanWord($filename);
  7.  
  8.  
  9. sub parseAndScanWord
  10. {
  11.     my ($fileName) = @_;
  12.  
  13.     my $document = Win32::OLE -> GetObject($fileName) or return;
  14.     my $paragraphs = $document->Paragraphs();
  15.     my $enumerate = new Win32::OLE::Enum($paragraphs);
  16.     while(defined(my $paragraph = $enumerate->Next()))
  17.     {
  18.         $text = $paragraph->{Range}->{Text};
  19.     }
  20. }
Reply