I assume your trying to read the excel sheet and not write to it
First look for XLS.rb and make life easy, then follow this code
fragment
XLS.rb has some nice methods to make life easier.

Alternatives are using ruby-roo


require 'rubygems'
require 'watir'
require './xls.rb'

#############################
# Assume a spreasheet named theSpreadsheet.xls
# It contains A header in A1 'LOGIN' and data in A2..A10.\
# It contains a Header in B2 'PASSWORD' and data in B2..B10
# That cell range was named Lookup_Terms in the spreadsheet
# The worksheets page is named: Terms
# XLS.rb will return a hash array to the main
#############################

def loadSpreadsheetData
        sSpreadsheet='theSpreadsheet.xls'
        sSheetname='Terms'
        sRange='Lookup_Users'    # or A1..A10
        myData = []
        myData=xls_GetTheRowData(myData,sSpreadsheet,sRange,sSheetname)
        # This is a method in xls.rb
        puts ' - Data Set Details'
        puts ' - Spreadsheet Source: '+sSpreadsheet.to_s
        puts ' - Data Range: '+sRange.to_s
        puts ' - Sheet Name: '+sSheetname.to_s
        puts ' - Rows: '+myData.length().to_s
        puts ' '
        return myData
end

myUser=[]
myUser=loadSpreadsheetData
iExcel=0
myUser.each {
  sLogin=myUser[iExcel].fetch('LOGIN').to_s
  sPassword=myUser[iExcel].fetch('PASSWORD'),to_s
  puts ' - Login: '+sLogin
  puts ' - Password: '+sLogin
  iExcel=iExcel+1
}
exit



On Feb 22, 9:52 pm, keneda 45 <widiz...@gmail.com> wrote:
> Hello,
>
> it's my file Excel :
>
> 10      "Limousin"
> 11      "Lorraine"
> 12      "Midi-Pyrénées"
> 13      "Nord-Pas de Calais"
> 14      "Basse Normandie"
> 15      "Haute Normandie"
> 16      Pays de la loire
> 17      "Picardie"
> 18      "Poitou-Charentes"
> 19      "Provence-Alpes-Côte d'Azur"
> 20      "Rhone-Alpes"
> 21      "Corse"
> 22      "Outre Mer et Etranger"
>
> and it's my script :
>
> require 'watir'
> require 'win32ole'
>
> puts "Choisir Region
>
> 10=Limousin
> 11=Lorraine
> 12=Midi-Pyrenees
> 13=Nord-Pas de Calais
> 14=Basse Normandie
> 15=Haute Normandie
> 16=Pays de la loire
> 17=Picardie
> 18=Poitou-Charentes
> 19=Provence-Alpes-Cote d'Azur
> 20=Rhone-Alpes
> 21=Corse
> 22=Outre Mer et Etranger
> ?"
> region=gets # I ask to enter a number between 10 to 22
>
> excel = WIN32OLE::new('excel.Application')
> excel.DisplayAlerts = false
> excel.Visible = 1
> workbook = excel.Workbooks.Open('C:\Ruby191\rv.xls')
>
> for i in 1 .. workbook.Worksheets.Count
>
>   worksheet = workbook.Worksheets(i)
>    rowcount = worksheet.UsedRange.Rows.Count
>   for j in 1..rowcount
>
> num =worksheet.Cells(j, 1).value
> nu=num.round(0)
>
> if nu=region
>
> puts worksheet.Cells(j, 2).value
>
> end
> end
> end
>
> with that script it array all worksheet.Cells(j, 2).value, I don't
> know how to array only worksheet.Cells(j, 2).value where nu=region
>
> Do you have an idea?
>
> thx

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to