Skip to content

Instantly share code, notes, and snippets.

@vmi
Created December 13, 2011 06:55
Show Gist options
  • Save vmi/1470974 to your computer and use it in GitHub Desktop.
Save vmi/1470974 to your computer and use it in GitHub Desktop.
[snippet] WIN32OLE Word (ruby)
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'win32ole'
WIN32OLE.codepage = WIN32OLE::CP_UTF8
$fso = WIN32OLE.new('Scripting.FileSystemObject')
$wd = WIN32OLE.new('Word.Application')
at_exit {
$wd.Quit
}
def get_absolute_path filename
$fso.GetAbsolutePathName(filename)
end
def dump_word filename
path = get_absolute_path(filename)
doc = $wd.Documents.Open(path, true)
begin
count = $wd.ActiveWindow.ActivePane.Pages.Count
puts "#{filename},#{count}"
ensure
doc.Close
end
end
ARGV.each do |filename|
dump_word(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment