Hello,

I want to get some values from a range in Excel using WatiR.
Here is my range:

pnr = worksheet.Range("i2:i4").Value

First I wonder how I could remove decimals i.e. convert all these
values during the execution of the code above.

Using to_i gives me the error that the method does not supprt arrays.

Can someone please show me how to iterate the code:

pnr = worksheet.Range("i2:i4").Value

and converting each value to an int (removing decimals) in some kind
of loop. In my case, value (zip code) 0354 is typed into a cell by me,
and the cell removes the first 0, but when I print it in Ruby, with
'puts', it yields 354,0.

Even better would be how do I iterate over a coloumn to there are no
more values left in that spesific coloumn and convert each value to
int format?

The entire code is pasted below if someone want to try it


Cheers!

********************************************************************************************************************

excel = WIN32OLE::new("excel.Application")
workbook = excel.Workbooks.Open("C:\\Programfiler\\Ruby\\FPSdata.xls")
worksheet = workbook.WorkSheets(1)

# Alle variabler blir lagt til egne Array's
site = worksheet.Range("a2:a4").Value
val = worksheet.Range("b2:b4").Value
txt = worksheet.Range("c2:c4").Value
fname = worksheet.Range("d2:d4").Value
lname = worksheet.Range("e2:e4").Value
fodsel = worksheet.Range("f2:f4").Value
bnk = worksheet.Range("g2:g4").Value
adr = worksheet.Range("h2:h4").Value
pnr = worksheet.Range("i2:i4").Value.to_i
pstd = worksheet.Range("j2:j4").Value
mo = worksheet.Range("k2:k4").Value
ep = worksheet.Range("l2:l4").Value
valitxt = worksheet.Range("m2:m4").Value

workbook.Close
excel.Quit

###### DATA-DREVET TESTING ######
######  Løkke for å gå gjennom arrayen tilsvarende ganger det finnes
elementer i arrayen  ######
count = 0
while count < (val.length)
test_site = site[count].to_s
val[count] = val[count].to_s.to_i
tekst = txt[count].to_s
firstname = fname[count].to_s
lastname = lname[count].to_s
fnr = fodsel[count].to_s
bank = bnk[count].to_s
adresse = adr[count].to_s
postnr = pnr[count].to_s

puts postnr

le = postnr.length
if le == 3
  puts "  Postnummeret er kun 3 siffer og jeg legger til en 0 foran"
  trall = postnr
  trall = '0' + postnr
  postnr = trall
else
  puts postnr
  puts "  Postnummer starter ikke med 0: " + postnr
end

poststed = adr[count].to_s
mobil = mo[count].to_s
epost = ep[count].to_s



# Logikken (Bruker en vilkårlig lengde (antall instanser/rader av
testdata) på en array som stopping-condition for antall test cases som
skal kjøres)
ie = Watir::IE.new
ie.goto test_site
ie.text_field(:name, "trust-121212124878").set val[count].to_s
ie.button(:id, "calculatorSubmit").click

# Validering
if ie.text.include? tekst
  puts "  Test NR. " + (count+1).to_s + " PASSED! Fant string: " +
tekst
else
  puts "  Test NR. " + (count+1).to_s + " FAILED! Fant ikke string: "
+ tekst
end

# Legger inn personopplysninger
ie.text_field(:name, "firstName").set firstname
ie.text_field(:name, "lastName").set lastname
ie.text_field(:name, "nationalIdentificationNumber").set fnr
ie.text_field(:name, "bankAccountNumber").set bank
ie.text_field(:name, "address").set adresse
ie.text_field(:name, "postalCode").set postnr
ie.text_field(:name, "postalPlace").set poststed
ie.text_field(:name, "mobilePhone").set mobil
ie.text_field(:name, "email").set epost
ie.text_field(:name, "conformingEmail").set epost
ie.button(:name, "action").click

ie.close();
count += 1 #inkrementerer med 1 for hver runde kjørt

end



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to