# Read from XLS and substitute values in Ruby (Watir)

**URL:** <https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936>\
**Category:** Ruby\
**Created:** [September 8, 2006, 1:29am UTC](https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936 "2006-09-08T01:29:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snoops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@snoops](https://www.ruby-forum.com/u/snoops)\
**Post date:** [September 8, 2006, 1:29am UTC](https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936/1 "2006-09-08T01:29:37Z")

</div>

Hello there,  
I am trying to read multiple columns from an xls file and substiture  
those values into a text\_field

Ex: My xls contains  
User Name password  
aaa abc321  
bbb abc123

I need to pass each row of records into a text\_fields for username and  
password and click on go…

I need to do this till the end of the file… could somebody tell me as  
to how I parameterize the values for the text fields so that it  
automatically picks up the records for each row…

Any help is greatly appreciated.

Thank you,  
MN

---

<div class="post-metadata">

**Author:** ![snoops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@snoops](https://www.ruby-forum.com/u/snoops)\
**Post date:** [September 8, 2006, 3:00am UTC](https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936/2 "2006-09-08T03:00:34Z")

</div>

Madu Nar wrote:

> I need to pass each row of records into a text\_fields for username and  
> password and click on go…
> 
> I need to do this till the end of the file… could somebody tell me as  
> to how I parameterize the values for the text fields so that it  
> automatically picks up the records for each row…

In your example above, one of the field names is “User Name”, with a  
space.  
Yet the field separator for the data records below it appears to uses  
one  
or more spaces as delimiters. On the other hand, it might be tabs, hard  
to  
tell from your post.

Let’s assume that tabs are used instead of spaces between the fields. If  
that is true, then (untested):

File.read(“filename”).each do |record|  
record.split("\t").each do |field|  
# your turn  
end  
end

---

<div class="post-metadata">

**Author:** ![snoops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@snoops](https://www.ruby-forum.com/u/snoops)\
**Post date:** [September 11, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936/3 "2006-09-11T19:26:29Z")

</div>

Hello Paul,  
Thank you so much for the Info…  
I tried and it did work. But, how do I pass each of those split  
tokens as separate parameters for the text fields.

Ex: ie.text\_field(:name,  
“SearchFormHandler.searchTerms”).set(“Brian Kantz”)  
ie.select\_list(:name,  
“SearchFormHandler.state”).select(“California”)

So the values Brian Kantz, California should be automatically  
substituted from the file… Your help is greatly appreciated…

Thanks,  
Madu

Paul L. wrote:

> Madu Nar wrote:
> 
> > I need to pass each row of records into a text\_fields for username and  
> > password and click on go…
> > 
> > I need to do this till the end of the file… could somebody tell me as  
> > to how I parameterize the values for the text fields so that it  
> > automatically picks up the records for each row…
> 
> In your example above, one of the field names is “User Name”, with a  
> space.  
> Yet the field separator for the data records below it appears to uses  
> one  
> or more spaces as delimiters. On the other hand, it might be tabs, hard  
> to  
> tell from your post.
> 
> Let’s assume that tabs are used instead of spaces between the fields. If  
> that is true, then (untested):
> 
> File.read(“filename”).each do |record|  
> record.split("\t").each do |field|  
> # your turn  
> end  
> end

---

<div class="post-metadata">

**Author:** ![snoops](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@snoops](https://www.ruby-forum.com/u/snoops)\
**Post date:** [September 11, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/read-from-xls-and-substitute-values-in-ruby-watir/67936/4 "2006-09-11T19:35:49Z")

</div>

Also,Is there a way to read from csv file or xls file because currently  
I am trying to read from a txt file.  
Should I Require/import any particular libraries before trying to read  
from a CSV or an xls file.  
Any help appreciated.

Thanks again,  
Madu

Madu Nar wrote:

> Hello Paul,  
> Thank you so much for the Info…  
> I tried and it did work. But, how do I pass each of those split  
> tokens as separate parameters for the text fields.
> 
> Ex: ie.text\_field(:name,  
> “SearchFormHandler.searchTerms”).set(“Brian Kantz”)  
> ie.select\_list(:name,  
> “SearchFormHandler.state”).select(“California”)
> 
> So the values Brian Kantz, California should be automatically  
> substituted from the file… Your help is greatly appreciated…
> 
> Thanks,  
> Madu
> 
> Paul L. wrote:
> 
> > Madu Nar wrote:
> > 
> > > I need to pass each row of records into a text\_fields for username and  
> > > password and click on go…
> > > 
> > > I need to do this till the end of the file… could somebody tell me as  
> > > to how I parameterize the values for the text fields so that it  
> > > automatically picks up the records for each row…
> > 
> > In your example above, one of the field names is “User Name”, with a  
> > space.  
> > Yet the field separator for the data records below it appears to uses  
> > one  
> > or more spaces as delimiters. On the other hand, it might be tabs, hard  
> > to  
> > tell from your post.
> > 
> > Let’s assume that tabs are used instead of spaces between the fields. If  
> > that is true, then (untested):
> > 
> > File.read(“filename”).each do |record|  
> > record.split("\t").each do |field|  
> > # your turn  
> > end  
> > end
