2

Is there a way when using roo to get the coordinates of a cell (or just the row) containing a predefined value?

For instance, having cell A,3 with content "HERE", I need, passing "HERE" to get (A,3) or just 3.

Thanks.

Sig
  • 5,476
  • 10
  • 49
  • 89
  • I'm afraid that your only option is to search the file for any cell containing that particular value. – yorodm Jan 24 '17 at 13:06

1 Answers1

1

I used roo for the first time today, and it doesn't feel Rubyish at all. There might be a better way, but this code worked fine for a simple example :

require 'roo'

xlsx = Roo::Excelx.new("roo.xlsx")

cell = xlsx.each_row_streaming.to_a.flatten.find do |c|
  c.value.to_s.include?('hello')
end

if cell
  p cell.coordinate
  #=> #<Roo::Excelx::Coordinate:0x000000028ea6a0 @row=6, @column=1>
  p cell.value
  #=> "hello world"
end

Note that it reads the whole spreadsheet even if the first cell is a match.

Eric Duminil
  • 52,989
  • 9
  • 71
  • 124