require 'win32ole'
fns = Dir.glob("*.xls")
application = WIN32OLE.new("excel.application")
application.visible = TRUE
f = File.new('errorCauseEN.xml','w')
f.puts('<?xml version="1.0" encoding="utf-8"?>')
f.puts('<!-- edited with XMLSPY v5 U (http://www.xmlspy.com) by et8 (et8) -->')
f.puts('<Category>')
fns.each do |file|
workbook = application.WorkBooks.Open(Dir.pwd + '/' + file)
sheet = workbook.WorkSheets(2)
sheet.Activate
i = 2
loop do
break if !sheet.Range('A'+ i.to_s).Value
break if !sheet.Range('C'+ i.to_s).Value
errname = sheet.Range('A'+ i.to_s).Value.to_s.hex.to_i.to_s.strip
valuename = sheet.Range('C'+ i.to_s).Value.strip
valuename.gsub!(//"/,'/'')
f.puts(' '*4 + '<ErrorCode name="' + errname + '" value="' + valuename +'"/>')
i = i + 1
end
puts file.to_s + ' is OK!'
workbook.close(0)
end
f.puts('</Category>')
f.close
application.Quit()
#workbook = application.WorkBooks.Open('D:/ErrorCase/TR_ErrCode.xls')
--------------------------------------------------------------------------
require 'win32ole'
require 'rexml/document'
include REXML
include REXML::
#fns = Dir.glob("*.xls")
#
application = WIN32OLE.new("excel.application")
#
application.visible = TRUE
#
#fns.each do |file|
# workbook = application.WorkBooks.Open(Dir.pwd + '/' + file)
#
#end
#
f = File.new('errorC.xml','w')
doc = Document.new('<Category />')
workbook = application.WorkBooks.Open('D:/ErrorCase/TR_ErrCode.xls')
sheet = workbook.WorkSheets(2)
sheet.Activate
i = 2
loop do
break if !sheet.Range('A'+ i.to_s).Value
ec = Element.new('ErrorCode')
ec.add_attribute('name',sheet.Range('A'+ i.to_s).Value.to_s.hex.to_i.to_s)
ec.add_attribute('value',sheet.Range('C'+ i.to_s).Value)
doc.root.add_element(ec)
i = i + 1
end
doc.write(f)
f.close