Skip to content

Instantly share code, notes, and snippets.

@y-yagi
Created February 25, 2012 13:53
Show Gist options
  • Save y-yagi/1908583 to your computer and use it in GitHub Desktop.
Save y-yagi/1908583 to your computer and use it in GitHub Desktop.
カレントディレクトリ配下のExcelを全て印刷するRubyスクリプト
# -*- coding: cp932 -*-
require 'find'
require 'win32ole'
def getAbsolutePath filename
fso = WIN32OLE.new('Scripting.FileSystemObject')
return fso.GetAbsolutePathName(filename)
end
xl = WIN32OLE.new('Excel.Application')
xl.DisplayAlerts = false
xl.Visible = true
Find.find('.') do |file|
next unless file.match(/\.xlsx?\z/)
book = xl.Workbooks.Open(getAbsolutePath(file))
book.Worksheets.select
book.PrintOut
book.Close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment