Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is the full code:
use strict; use Text::Wrap; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Enum; die "Usage: perl test.doc" unless @ARGV == 1; my $File = $ARGV[0]; $File = Win32::GetCwd() . "/$File" if $File !~ /^(\w:)?[\/\\]/; die "File $ARGV[0] does not exist" unless -f $File; my $Word = Win32::OLE->new('Word.Application', 'Quit') or die "Couldn't run Word"; my $Doc = $Word->Documents->Open($File); my (@words, $nwords, @chars, $nchars, $len, $object, $paragraph, $para +graph_count, $enum, $allText, $para_temp); my $lc=0; my $pc=0; my (@char, $char); $enum = Win32::OLE::Enum->new($Doc->Paragraphs); allText = ''; $para_temp = 0; while(($object = $enum->Next)) { $para_temp++; $paragraph = $object->Range->{Text}; $allText .= $paragraph; chop $paragraph; unless ($paragraph eq '') { $paragraph_count++; } chomp $paragraph; @words = split /\s+/, $paragraph; $nwords += @words; @chars = split //, $paragraph; $nchars += @chars; } $allText =~ tr/\t //d; $len = length($allText) - $para_temp; printf "Character (no spaces) %d\n", $nchars; printf "Character (wout spaces) %d\n", $len; printf "Character (words) %d\n", $nwords; printf "Character (paragraphs) %d\n",$paragraph_count; printf "Line Count %d\n", $lc; printf "Page Count %d\n", $pc; $Doc->Close;
Just let me know how can i count the $lc(line count) and $pc (page count)?

Thanks Nicholas

Edited by Chady -- added code tags.

In reply to Re: Re: How to get MS-Word Page count and line count? by nicholas
in thread How to get MS-Word Page count and line count? by nicholas

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-06-06 12:28 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.