DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 23 posts at DZone. View Full User Profile

Ruby & MS Word: Counting Words And Pages

06.22.2009
| 1240 views |
  • submit to reddit
        From the <a href="http://rubyonwindows.blogspot.com">Ruby on Windows</a> blog...

require 'win32ole'

WdStatisticWords = 0
WdStatisticPages = 2

word = WIN32OLE.connect('Word.Application')
doc = word.ActiveDocument
word_count = doc.ComputeStatistics(WdStatisticWords)
page_count = doc.ComputeStatistics(WdStatisticPages)

Further details <a href="http://rubyonwindows.blogspot.com/2009/06/ruby-word-counting-words-and-pages.html">here</a>.