Hi Monks, I am trying to extract the some information from the group of docx file. So I first convert the docx to text file using Win32::OLE. The problem is when I have to run the program Second time, I have to close the "Winword.exe" manually from taskmanager. I suspect its clearly because we are not closing the Word Application in script properly.
Below is the code snippet, any help on to close the Word application would be greatful.
open(OUTFILE2,">Author_name_extract.txt") or die("Cant open Output fil
+e\n");
@filesnames = glob '*.docx';
foreach $count (@filesnames) #Loop till the end is reached
{
$filename = "D:\\MRJ_BCU\\Perl\\From thejaswini\\doc_read\\$count"
+;
$document = Win32::OLE -> GetObject($filename);
my $app = $document->{Application};
open(OUTFILE1,">File_under_Review.txt") or die("Cant open Output f
+ile\n");
print "Extracting Text from $filename...\n";
$paragraphs = $document->Paragraphs();
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{
$a = $paragraph->{Range}->{Text};
print OUTFILE1 "$a\n";
}
close(OUTFILE1);
$#document->Close();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.