Re: [Wtr-general] Reading from excel files (basic)
Thanks very much, managed to sort it now. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
if you are only getting 4 cells, why the array show a long list with nil. your are missing something here. Check your code again! ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
Hi Nicola, you could try something like this: excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\Documents and Settings\kennedyn\My Documents\WATIR_RUBY\excel _testdata2.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select [EMAIL PROTECTED] = [] [EMAIL PROTECTED] = worksheet.Range('a1:z1').value # The data is in cell a1. #puts @mydata # to c wether the content is in the array. excel['Visible'] = true # hide the spreadsheet from view line = '1' while val = worksheet.Range("a#{line}")['Value'] #pull the value stored in the cell while it's valid ie.goto(val)#use the value line.succ! #update the line number end This will only loop through for the first column a(1-end of valid values). You can expand it to pull an array if you want. -Charley workbook.close excel.Quit On 3/26/07, Nicola Kennedy <[EMAIL PROTECTED]> wrote: Hi, I did this and the logs showed the websites as follows: ... ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
Hi, I did this and the logs showed the websites as follows: www.google.co.uk www.freeuk.com www.bbc.co.uk www.manilow.com nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil The test then just ends, with no errors, but the test doesn't take me to the four websites. As an aside as well, I don't want it to enter nil as the web address, so is there a way once this is fixed, that it knows to stop putting stuff into the array when the next cell is empty. Have pasted script as it stands below excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\Documents and Settings\kennedyn\My Documents\WATIR_RUBY\excel_testdata2.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select @mydata = [] @mydata = worksheet.Range('a1:z1').value # The data is in cell a1. puts @mydata # to c wether the content is in the array. excel['Visible'] = true # hide the spreadsheet from view workbook.close excel.Quit # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data #ie.goto('http://' + @mydata) # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data @mydata.length do |x| ie.goto('http://' + @mydata[x]) end TIA ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
try this @mydata = worksheet.Range('a1:a4').value puts @mydata # to c wether the content is in the array. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
Hi, Have done this, but am getting error: 1) Error: test_recorded(TC_recorded): NoMethodError: undefined method `length' for nil:NilClass testnic2.rb:50:in `test_recorded' Have copied my script again in case I've done something wrong? excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\Documents and Settings\kennedyn\My Documents\WATIR_RUBY\excel_testdata.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select @mydata = [] @mydata = worksheet.Range('a1:a4')['text'] # The data is in cell a1. excel['Visible'] = true # hide the spreadsheet from view workbook.close excel.Quit # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data #ie.goto('http://' + @mydata) # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data @mydata.length do |x| ie.goto('http://' + @mydata[x]) end TIA ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Reading from excel files (basic)
$data = [] $data = worksheet.Range('a1:z1')'text' # The data is in cell a1. excel'Visible' = false # hide the spreadsheet from view workbook.close excel.Quit # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data $data.length do |x| ie.goto('http://' + $data[x]) end $data is not a good idea as the $ stands for global variable. If not needed to be global remove them and replace with @ or @@ as your definitions needs. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
[Wtr-general] Reading from excel files (basic)
Hi, I am completely new to WATIR, and don't have much programming experience so forgive the simplicity of this question! I am just learning the basics and have created a script that calls an excel file which has a column of web addresses. I have got the scripts to read in the first value from A1 and when executed, the script goes to that web address. My question is how do I set the script up to loop round reading in all the web addresses in the column, so it goes to each web address in turn and then finish when it gets to an empty line. My script looks like this at the minute: require 'win32ole' excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\Documents and Settings\kennedyn\My Documents\WATIR_RUBY\excel_testdata.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select #bring it to the front -need sometimes to run macros, not for working with a worksheet from ruby excel['Visible'] = false #make visible, set to false to make invisible again. Don't need it to be visible for script to work excel = WIN32OLE::new('excel.Application') workbook = excel.Workbooks.Open('C:\Documents and Settings\excel_testdata.xls') worksheet = workbook.Worksheets(1) #get hold of the first worksheet worksheet.Select $data = worksheet.Range('a1')['text'] # The data is in cell a1. excel['Visible'] = false # hide the spreadsheet from view workbook.close excel.Quit # Insert the data read from the spreadsheet into the text field #$ie.text_field(:name, 'TEST').set $data ie.goto('http://' + $data) TIA ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general