I write some code for Reading data from excel file and put into the
google.
but they give error plz help me.
ERROR:
Excel.rb:16: warning: already initialized constant Keyword
Excel.rb:17: warning: already initialized constant Object_Prop_Name
Excel.rb:18: warning: already initialized constant Object_Prop_Value
Excel.rb:19: warning: already initialized constant Expected_Output
Excel.rb:20: warning: already initialized constant Parm_01
Excel.rb:16: warning: already initialized constant Keyword
Excel.rb:17: warning: already initialized constant Object_Prop_Name
Excel.rb:18: warning: already initialized constant Object_Prop_Value
Excel.rb:19: warning: already initialized constant Expected_Output
Excel.rb:20: warning: already initialized constant Parm_01
Excel.rb:16: warning: already initialized constant Keyword
Excel.rb:17: warning: already initialized constant Object_Prop_Name
Excel.rb:18: warning: already initialized constant Object_Prop_Value
Excel.rb:19: warning: already initialized constant Expected_Output
Excel.rb:20: warning: already initialized constant Parm_01
require ‘watir’
include Watir
begin
#Open Excel File
excel = WIN32OLE::new(‘excel.Application’)
excel.DisplayAlerts = false
workbook = excel.Workbooks.Open(‘C:\test\POC.xls’)
#Loop through the worksheets
for i in 1 … workbook.Worksheets.Count
worksheet = workbook.Worksheets(i)
rowcount = worksheet.UsedRange.Rows.Count
for j in 2…rowcount
Keyword =worksheet.Cells(j, 1).value
Object_Prop_Name = worksheet.Cells(j, 2).value
Object_Prop_Value = worksheet.Cells(j, 3).value
Expected_Output = worksheet.Cells(j, 4).value
Parm_01 = worksheet.Cells(j, 6).value
case Keyword
when /^OpenURL/
ie=IE.start(Parm_01)
#~ @Browser.maximize
when /^SetText/
ie.text_field(:"#{Object_Prop_Name}",
Object_Prop_Value).set(Parm_01)
when/^ClickButton/
ie.button(:"#{Object_Prop_Name}", Object_Prop_Value).click
when/^ClickLink/
ie.link(:"#{Object_Prop_Name}", Object_Prop_Value).click
when/^CloseURL/
ie.close
end
end
end
workbook.Close()
excel.quit()
rescue
workbook.Close()
excel.quit()
end
Keyword, Object_Prop_Name … there are constant values in Ruby.
You should use lower case charset for valiable name. (e.g. keyword,
object_prop_name)
Thanks.
2010/5/13 KingMaker KingMaker [email protected]:
Ayumu A. wrote:
Keyword, Object_Prop_Name … there are constant values in Ruby.
You should use lower case charset for valiable name. (e.g. keyword,
object_prop_name)
Thanks.
Hi i try with lower case charset but program not run.
Hi,
plz post now virsion of your program.
2010/5/13 KingMaker KingMaker [email protected]:
require ‘watir’
include Watir
begin
#Open Excel File
excel = WIN32OLE::new(‘excel.Application’)
excel.DisplayAlerts = false
workbook = excel.Workbooks.Open(‘C:\test\POC.xls’)
#Loop through the worksheets
for i in 1 … workbook.Worksheets.Count
worksheet = workbook.Worksheets(i)
rowcount = worksheet.UsedRange.Rows.Count
for j in 2…rowcount
keyword =worksheet.Cells(j, 1).value
object_prop_name = worksheet.Cells(j, 2).value
object_Ppop_value = worksheet.Cells(j, 3).value
expected_output = worksheet.Cells(j, 4).value
parm_01 = worksheet.Cells(j, 6).value
case keyword
when /^OpenURL/
ie=IE.start(Parm_01)
#~ @Browser.maximize
when /^SetText/
ie.text_field(:"#{object_prop_name}",
object_Ppop_value).set(parm_01)
when/^ClickButton/
ie.button(:"#{object_prop_name}", object_Ppop_value).click
when/^ClickLink/
ie.link(:"#{object_prop_name}", object_Ppop_value).click
when/^CloseURL/
ie.close
end
end
end
workbook.Close()
excel.quit()
rescue
workbook.Close()
excel.quit()
end
also i attach the execl file plz have a look
gem 0.9.4
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
So are you getting the same warning messages?? Since those were
Warnings and not Errors, your program should still have done something.
When you say its not running, are you getting errors, or it not working
the way you want it to??
– john
This program may be your want, but also you can use Selenium or
Mechanize.
see below
require ‘rubygems’
require ‘win32ole’
require ‘watir’
include Watir
begin
#Open Excel File
excel = WIN32OLE::new(‘excel.Application’)
excel.DisplayAlerts = false
workbook = excel.Workbooks.Open(‘C:\tmp\POC.xls’)
#Loop through the worksheets
for i in 1 … workbook.Worksheets.Count
worksheet = workbook.Worksheets(i)
rowcount = worksheet.UsedRange.Rows.Count
for j in 2..rowcount
keyword =worksheet.Cells(j, 1).value
object_prop_name = worksheet.Cells(j, 2).value
object_Ppop_value = worksheet.Cells(j, 3).value
expected_output = worksheet.Cells(j, 4).value
parm_01 = worksheet.Cells(j, 6).value
case keyword
when /^OpenURL/
ie=IE.start(parm_01)
#~ @Browser.maximize
when /^SetText/
ie.text_field(:"#{object_prop_name}",object_Ppop_value).set(parm_01)
when/^ClickButton/
ie.button(:"#{object_prop_name}", object_Ppop_value).click
when/^ClickLink/
ie.link(:"#{object_prop_name}", object_Ppop_value).click
when/^CloseURL/
ie.close
end
end
end
workbook.Close()
excel.quit()
rescue
workbook.Close()
excel.quit()
end
Ayumu AIZAWA
http://twitter.com/ayumin
2010/5/13 John A. [email protected]: