Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
My bad!

As you probably know TIMTOWTDI. When I had time to test what I had posted earlier I discoverd that it is generating raw statistics, counting EOL and everything. I am assuming that you want the statistics that are availabile from the properties of that document. The code below will do what you want.

I used the fuctions available within the application to do the work. This will usually work better for you when you are comunicating between applications.

And thanks for posting the code!
use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Enum; # Here you have to call the file with "Name.pl C:\dir\file.doc" # This will allow you to point the script anywere rather than # having to put the script into the dir with the file. die "Usage: perl doc_print.pl test.doc" unless @ARGV == 1; my $Word = Win32::OLE->new( 'Word.Application', 'Quit' ) || die "Could +n't run Word"; my $Doc = $Word->Documents->Open(@ARGV[0]) || die "File does not exist + or can not be opened"; # Selection can be the entire doc or refined to a sub-set of text # It is easier to use the functions that exist in word to do the work. my $num_pages = $Doc->ComputeStatistics(wdStatisticPages); my $num_paragraphs = $Doc->ComputeStatistics(wdStatisticParagraphs); my $num_lines = $Doc->ComputeStatistics(wdStatisticLines); my $num_words = $Doc->ComputeStatistics(wdStatisticWords); my $num_chars = $Doc->ComputeStatistics(wdStatisticCharacters); my $num_charWs = $Doc->ComputeStatistics(wdStatisticCharactersWith +Spaces); printf "Page Count %d\n", $num_pages; printf "Character (paragraphs) %d\n", $num_paragraphs; printf "Line Count %d\n", $num_lines; printf "Character (words) %d\n", $num_words; printf "Character (with spaces) %d\n", $num_charWs; printf "Character (wout spaces) %d\n", $num_chars; $Doc->Close;

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

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found