From: Thomas Le Date: 2011-10-06T13:04:26+09:00 Subject: Re: comparing elements in same array --90e6ba6136b8036f6e04ae996aa0 Content-Type: text/plain; charset=ISO-8859-1 I want to find (thousands of) duplicate names in the spreadsheet so I can compare the corrresponding files to see if they produce the same results ... my logic is like this "if name in column A row 2 is same as that in colum A row 3, open files in column B row 2 and column B row 3,...do something else" ... Thanks, TL On Thu, Oct 6, 2011 at 2:26 AM, botp wrote: > On Thu, Oct 6, 2011 at 10:02 AM, Thomas Le wrote: > > require 'roo' > > ORGFILE = 'organize.xlsx' > > xcel = Excelx.new("#{ORGFILE}") > > lose the inlining hash, just do > xcel = Excelx.new(ORGFILE) > > same w others below.. > > > xcel.default_sheet = xcel.sheets.first > > startingRow = 2 > > nameArray = [] > > nameProfile = Hash.new > > startingRow.upto(xcel.last_row) do |row| > > name = xcel.cell(row,'A') > > location = xcel.cell(row,'B') > > nameProfile["#{name}"] = "#{location}" > > at this point, since you are associating the name to the location, you > are assumming that the name is unique, ie each name has one and only > one location. now what if you're wrong? > > > nameArray.push("#{name}") > > startingRow += 1 > > end > > hmm, finding duplicates names in nameArray is so obvious. why do you > want it? to remove duplicate rows in your excel file? .... or maybe, > you may also want to know duplicate names but different location, no? > > kind regards -botp > > --90e6ba6136b8036f6e04ae996aa0--