List Info

Thread: Looping with excel worksheets




Looping with excel worksheets
country flaguser name
United States
2007-04-13 08:16:44
Hi,

Have written following script (which works! I'm getting
there!)
I now want to put a loop in so that when this is complete,
it goes to the second worksheet in my excel file, basically
starting the process from the beginning again and then
inputs this information in the same fields.

Can anyone help?

TIA

require 'watir'
include Watir

url = "http://www.zoomerang.com/recipient/survey.zg
i?p=WEB225WDYJNVDT"
search_string = "questionnaire"

ie = IE.new
ie.goto(url)
ie.bring_to_front
#ie.show_all_objects

require 'win32ole'

excel = WIN32OLE::new('excel.Application')
        workbook =
excel.Workbooks.Open('C:WATIR_RUBYexcel_testdata5.xls')


        worksheet = workbook.Worksheets(1) #get hold of the
first worksheet
        worksheet.Select
        mydata = []
        mydata = worksheet.Range('a1:a6').value # The data is
in cell a1 - a6
        excel['Visible'] = false # hide the spreadsheet from
view
        workbook.close
        excel.Quit


ie.text_field(:name, 'u_answer_58').set(mydata[0].to_s)
ie.text_field(:name, 'u_answer_59').set(mydata[1].to_s)
ie.text_field(:name, 'u_answer_60').set(mydata[2].to_s)
ie.text_field(:name, 'u_answer_61').set(mydata[3].to_s)
ie.text_field(:name, 'u_answer_62').set(mydata[4].to_s)
ie.text_field(:name, 'u_answer_63').set(mydata[5].to_s)
_______________________________________________
Wtr-general mailing list
Wtr-generalrubyforge.org
htt
p://rubyforge.org/mailman/listinfo/wtr-general

Re: Looping with excel worksheets
user name
2007-04-13 10:03:23
Hi Nicola,

  Put it in a method and call the method from within a loop:

require 'watir'
include Watir

url = "http://www.zoomerang.com/recipient/survey.zgi?p=WEB225WDYJNVDT "
search_string = "questionnaire"

$ie = IE.new
$ie.goto(url)
$ie.bring_to_front
#ie.show_all_objects

require 'win32ole'

def fill_fields(worksheet_no)

 ; excel = WIN32OLE::new(' excel.Application')
  workbook = excel.Workbooks.Open('C:WATIR_RUBYexcel_testdata5.xls')

  worksheet = workbook.Worksheets(worksheet_no) #get hold of the first worksheet
  worksheet.Select
  mydata = []
 ; mydata = worksheet.Range('a1:a6').value # The data is in cell a1 - a6
  excel[';Visible9;] = false # hide the spreadsheet from view
 ; workbook.close
  excel.Quit


  $ie.text_field(:name, 'u_answer_58').set(mydata[0].to_s)
  $ie.text_field(:name, 'u_answer_59').set(mydata[1].to_s)
 ; $ie.text_field(:name, 'u_answer_60').set(mydata[2].to_s)
 ; $ie.text_field(:name, 'u_answer_61').set(mydata[3].to_s)
 ; $ie.text_field(:name, 'u_answer_62').set(mydata[4].to_s)
  $ie.text_field(:name, 'u_answer_63').set(mydata[5].to_s)
end

# call the method:
for i in 1..5
 ; fill_fields(i)
end


Note that I've changed ie to $ie making it global so it's visible inside the method.


-Charley

On 4/13/07, Nicola Kennedy < forum-watir-usersopenqa.org">forum-watir-usersopenqa.org> wrote:
Hi,

Have written following script (which works! I'm getting there!)
I now want to put a loop in so that when this is complete, it goes to the second worksheet in my excel file, basically starting the process from the beginning again and then inputs this information in the same fields.

Can anyone help?

TIA

require 'watir'
include Watir

url = "http://www.zoomerang.com/recipient/survey.zgi?p=WEB225WDYJNVDT "
search_string = "questionnaire&quot;

ie = IE.new
ie.goto(url)
ie.bring_to_front
#ie.show_all_objects

require 'win32ole'

excel = WIN32OLE::new('excel.Application ')
 &nbsp; &nbsp; &nbsp;  workbook = excel.Workbooks.Open('C:WATIR_RUBYexcel_testdata5.xls')


 &nbsp; &nbsp; &nbsp; &nbsp;worksheet = workbook.Worksheets(1) #get hold of the first worksheet
  ; &nbsp; &nbsp; &nbsp;worksheet.Select
&nbsp;   ; &nbsp; &nbsp;mydata = []
 ; &nbsp; &nbsp; &nbsp; mydata = worksheet.Range('a1:a6').value # The data is in cell a1 - a6
 &nbsp;   ; &nbsp; excel['Visible'] = false # hide the spreadsheet from view
 ; &nbsp; &nbsp; &nbsp; workbook.close
 &nbsp; &nbsp;   ; excel.Quit


ie.text_field(:name, 'u_answer_58').set(mydata[0].to_s)
ie.text_field(:name, 'u_answer_59').set(mydata[1].to_s)
ie.text_field(:name, 'u_answer_60').set(mydata[2].to_s)
ie.text_field (:name, 'u_answer_61').set(mydata[3].to_s)
ie.text_field(:name, 'u_answer_62').set(mydata[4].to_s)
ie.text_field(:name, 'u_answer_63').set(mydata[5].to_s)
_______________________________________________
Wtr-general mailing list
Wtr-generalrubyforge.org">Wtr-generalrubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )