#!/Perl/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Enum; use strict; print header; print start_html("Processing..."); print h3("Processing your request..."); my $text = param("search_text"); my $type = param("type"); print "You requested a search for the words \"$text\" in the documents + where they appear as $type...\n"; my $time = localtime; my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::O +LE->new('Word.Application', 'Quit'); my $infile = "<Word document here>"; $Word->Documents->Open($infile,{ReadOnly => 1}) || die("Unable to open + document ", Win32::OLE->LastError()); $Word->{visible} = 0; $Word->{DisplayAlerts} = 0; my $range = $Word->ActiveDocument->Content; my $current_song; my $flag; my @mytext; my @mystyle; my $compare; my % +song; my $song_count = 0; foreach my $word (in $range->Words){ push(@mytext,$word->{Text}); push(@mystyle,$word->{Style}->{NameLocal}); } for (my $x = 0;$x <= $#mytext; $x++) { my $current_song; my $current_writer; my $current_lyrics; if ($mystyle[$x] eq "Heading 1") { my $counter = 0; undef $current_song; while ($mystyle[$x+$counter] eq "Heading 1") { $current_song .= $mytext[$x+$counter]; $counter++; } $x += $counter; chop($current_song); chop($current_song); $song{Title}[$song_count] = $current_song; } elsif ($mystyle[$x] =~ /Songwriter/) { my $counter = 0; undef $current_writer; while ($mystyle[$x+$counter] =~ /Songwriter/) { $current_writer .= $mytext[$x+$counter]; $counter++; } $x += $counter; chop($current_writer); chop($current_writer); $song{Songwriter}[$song_count] = $current_writer; } else { my $counter = 0; undef $current_lyrics; while ($mystyle[$x+$counter] =~ /Lyrics|Chord/) { if ($mystyle[$x+$counter] eq "Lyrics") { $current_lyrics .= $mytext[$x+$counter]; } $counter++; } $song{Lyrics}[$song_count] = $current_lyrics; $song_count++; $x += $counter; } } print "<br><br>Matches:<ol>"; my $matching_song; for (my $x=0;$x<$song_count;$x++) { if (($type eq "Heading 1" and $song{Title}[$x] =~ /$text/i) or ($type eq "Lyrics" and $song{Lyrics}[$x] =~ /$text/i) or ($type eq "Songwriter" and $song{Songwriter}[$x] =~ /$text/i)) + { print "<li><b>$song{Title}[$x]:</b> <i>$song{Songwriter}[$x]< +/i>\n"; print "<ul><li><pre>$song{Lyrics}[$x]</pre>\n"; print "<li><a href=\"gen_song.pl?title=$song{Title}[$x]&format +=doc\">$song{Title}[$x].doc</a>\n"; print "<li><a href=\"gen_song.pl?title=$song{Title}[$x]&format +=pdf\">$song{Title}[$x].pdf</a></ul>\n"; $matching_song = $x; } } print "</ol>"; print "<br><br><br><i><font color=blue>Query started at $time"; $time = localtime; print "<br>Query completed at $time"; print end_html; $Word->Quit(); undef $Word;

In reply to Re: OLE Word... by jpavel
in thread OLE Word... by jpavel

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.