# encoding: utf-8
require 'win32ole'
if ARGV.length != 4 then
abort "引数の数が正しくありません。\nruby edit_iraisho.rb 対象ディレクトリ 対象シート 対象セル 値"
end
@src_dir, @target_sheet, @target_cell, @value = ARGV
@src_dir = @src_dir.gsub(/\\/) {'/'}
p @src_dir
begin
excel = WIN32OLE.new('Excel.Application')
excel.visible = false
Dir.glob(@src_dir + '/*.xlsx') do |f|
f = File.expand_path(f)
wb = excel.Workbooks.Open(f)
sh = wb.Worksheets.Item(@target_sheet)
sh.Range(@target_cell).Value = @value.encode('utf-8', 'cp932')
wb.Save
wb.close
end
ensure
excel.Quit
end
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme