Created
December 13, 2011 06:56
-
-
Save vmi/1470977 to your computer and use it in GitHub Desktop.
[snippet] WIN32OLE Excel (ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'win32ole' | |
WIN32OLE.codepage = WIN32OLE::CP_UTF8 | |
$fso = WIN32OLE.new('Scripting.FileSystemObject') | |
$xl = WIN32OLE.new('Excel.Application') | |
at_exit { | |
$xl.Quit | |
} | |
def get_absolute_path filename | |
return $fso.GetAbsolutePathName(filename) | |
end | |
def dump_excel filename | |
path = get_absolute_path(filename) | |
book = $xl.Workbooks.Open(path, { 'ReadOnly' => true }) | |
begin | |
count = book.Worksheets.Count | |
puts "#{filename},#{count}" | |
$stdout.flush | |
ensure | |
book.Saved = true | |
book.Close | |
end | |
end | |
ARGV.each do |filename| | |
dump_excel(filename) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment