我的定义看起来像这样,
def Execute_Statement(obj_type,obj_name,obj_value,name)
sheet1 = book.worksheet 0
sheet1.each do |row|
break if row[0].nil?
if (obj_type == "Edit")
@browser.text_field(:obj_name => row[0]).when_present.set(name)
end
end
end
在我的excel中我有5列,看起来像这样,Execute_Statement“编辑”“id”“UserName”“name”,
我想知道是否可以通过excel调用ruby编写的方法
答案 0 :(得分:1)
require 'spreadsheet'
def execute_statement(obj_type, obj_name, obj_value, name)
# do something
end
book = Spreadsheet.open '/path/to/an/excel-file.xls'
sheet = book.worksheet(0)
sheet.each do |row|
execute_statement(row[0], row[1], row[2], row[3])
end