From: dtolj Date: 2010-10-15T03:38:32+09:00 Subject: Re: Excel and Ruby http://rubyonwindows.blogspot.com/search/label/excel On Oct 14, 2:23 pm, Daniel Navarro wrote: > Thank you very much! :) Like I said I am new, I found an example this > morning like that but haven't had time to play with it. Again thank you so > much. > > > > On Thu, Oct 14, 2010 at 1:19 PM, dtolj wrote: > > Why do you have a nested loop? > > You can do this in two ways > > 1) with activecell and offset to imitate moving around Excel sheet > > with a cursor > > 2) or something like this: > > line=1 > > while worksheet.range("q#{line}").value > >  worksheet.range("q#{line}").value > >  line=line+1 > > end > > > On Oct 13, 1:37 pm, Daniel Navarro wrote: > > > oops sorry I initialized alot of Constants there. > > > > anyways here is my updated code > > > > it works fine except it is returning multiple values of the result. Any > > > Ideas? > > > >   require 'win32ole' > > > xl = WIN32OLE.connect('Excel.Application') > > > wb = xl.ActiveWorkbook > > > ws = xl.ActiveSheet > > > ws.Range('N2').each do |cell| > > > ws.Range('P3501:V3501').each do |days| > > >   contentsN = cell.value > > >   cellContentsN = contentsN.scan(/\w+/) > > >   dayofweek = %w{Monday Tuesday Wednesday Thursday Friday Saturday > > Sunday} > > >   month = %w{Janurary Feburary March April May June July August September > > > October November December} > > >   comparedayofweek = dayofweek & cellContentsN > > >   comparemonth = month & cellContentsN > > > >   p comparedayofweek > > >   p comparemonth > > > > end > > > end > > > > On Wed, Oct 13, 2010 at 3:19 AM, Dan Sr. wrote: > > > > Hello all, > > > > > I'm just doing some data entry work and thought it would be fun to > > > > automate my work with Ruby.(yes I could do this in VB but what fun is > > > > that?) > > > > > What I am doing is putting column N into an Array. And then comparing > > > > the array to an already specified array to get the value. If that value > > > > is present then I want to put an X in column P-V, Time in w-x and dates > > > > in y-z. so far I have got everything that I have coded to work > > correctly > > > > but haven't put classes or any structure to it. Just wanted to see if > > > > what I was doing was ruby~esque so far and if anyone had any cool > > tricks > > > > or see something I am doing wrong. (My first program automating excel > > or > > > > really anything in ruby) I have automated some files with tutorials but > > > > this is my first attempt on automating anything for any relevant > > > > purpose. It's only half 1/4 or 1/8 written so far. > > > > My goal is to loop through the items one by one, incrementing +1 to the > > > > next cell until I reach the end of the file. > > > > if __FILE__ == $0 > > > >  # TODO Generated stub > > > >  require 'win32ole' > > > > xl = WIN32OLE.connect('Excel.Application') > > > > wb = xl.ActiveWorkbook > > > > ws = xl.ActiveSheet > > > > ws.Range('N1').each do |cell| > > > > ws.Range('P1:V1').each do |days| > > > >  ContentsN = cell.value > > > >  CellContentsN = ContentsN.scan(/\w+/) > > > >  Dayofweek = %w{Monday Tuesday Wednesday Thursday Friday Saturday > > > > Sunday} > > > >  Month = %w{Janurary Feburary March April May June July August > > > > September October November December} > > > >  01.upto(31){|Day|} > > > >  Comparedayofweek = Dayofweek & CellContentsN > > > >  Comparemonth = Month & CellContentsN > > > >  Compareday = Day & CellContentsN > > > >  end > > > > end > > > > end > > > > > -- > > > > Posted viahttp://www.ruby-forum.com/. > > > > -- > > > Daniel Navarro > > > 9035612340 > > -- > Daniel Navarro > 9035612340