Thanks for your advice munk.
Anyhow I am loading word constants within a package as
use WIN32::OLE::Const 'Microsoft Word';
The other thing is the constant in close method work perfectly; I checked it. If you have free enough time here's whole code
---------------------------------------------------
##################### # # Initiating program # ##################### use strict; use LTG::DocBuddy::OfficeSub; use File::Find; require Exporter; use vars qw(@ISA @EXPORT); my $dir = 'C:\sumith\project\test_data\input\word\small'; find(\&parse_office_doc, $dir);
---------------------------------------------------
##################### # # Office package to handle all # types of office files (but I # simplified it, yet give same # problem # ##################### package LTG::DocBuddy::OfficeSub; use strict; use diagnostics; use WIN32::OLE; use WIN32::OLE::Variant; require Exporter; use vars qw(@ISA @EXPORT); use LTG::DocBuddy::Config qw($DEBUG); use LTG::DocBuddy::WordSub; @ISA = qw(Exporter); @EXPORT = qw(parse_office_doc); $DEBUG && print "Loading LTG::DocBuddy::OfficeSub package...\n"; my ($word_app, $excel_app, $ppt_app, $access_app); $word_app = Win32::OLE->new('Word.Application', 'Quit(0)'); sub parse_office_doc { $DEBUG && print "Calling LTG::DocBuddy::OfficeSub->parse_office_do +c(@_) method...\n"; my $file = shift; my %file_info = (); my $obj; my $whole_text; if ($obj = $word_app->Documents->open($file, 0, 1)) { %file_info = read_doc_properties($obj); $file_info{'Style'} = {get_word_content($obj)}; foreach my $style (keys %{$file_info{'Style'}}) { $whole_text .= ${$file_info{'Style'}}{$style}; } delete $file_info{'Style'}; $obj->Close(0); } if (not $obj) { return { error => "$file: GetObject not successful: ". Win32::OLE->LastError() }; } $file_info{'Whole text'} = $whole_text; return %file_info; } sub read_doc_properties { $DEBUG && print "Calling LTG::DocBuddy::OfficeSub->read_doc_proper +ties(@_) method...\n"; my $obj = shift; my %file_info; if (my $properties = $obj->{BuiltInDocumentProperties}) { foreach my $prop (in $properties) { $file_info{$prop->{'Name'}} = "$prop->{'Value'}" if ($prop +->{'Value'}); } } return %file_info; } 1;
---------------------------------------------------
##################### # # Word handling package # ##################### package LTG::DocBuddy::WordSub; use strict; use WIN32::OLE; use WIN32::OLE::Variant; use WIN32::OLE::Const 'Microsoft Word'; require Exporter; use vars qw(@ISA @EXPORT); use LTG::DocBuddy::Config qw($DEBUG); @ISA = qw(Exporter); @EXPORT = qw(get_word_content); $DEBUG && print "Loading LTG::DocBuddy::WordSub package...\n"; sub get_word_content { $DEBUG && print "Calling LTG::DocBuddy::WordSub->get_word_content( +@_) method...\n"; my $obj = shift; my $enumerate = new Win32::OLE::Enum($obj->Paragraphs()); my %content; while(defined(my $paragraph = $enumerate->Next())) { $content{$paragraph->{Style}->{NameLocal}} .= "$paragraph->{Ra +nge}->{Text}\n\n"; } $enumerate->Reset(); return %content; } 1;
---------------------------------------------------
Thanks again for your attention and do you have any suggessions?


In reply to Re: Re: OLE word problem by banduwgs
in thread OLE word problem by banduwgs

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.