0

I'm currently using roo to read a set of spreadsheets. I'd like to be able to skip certain rows when I itterate over each one (to skip header rows, etc). Is there any way to do this? I figure I could just use an index in the loop, but I was wondering if there was a "roo" way to do it.

Something like:

spreadsheet.each(c1: "Column1", c2: "Column2") do |therow|
    next if therow.row(1)
end

Thanks!

neanderslob
  • 2,633
  • 6
  • 40
  • 82
  • have you tried using `parse` method? it will return only the rows matching to a certain regex – Minato Nov 19 '15 at 08:57

1 Answers1

0

To skip header row, you can start from 2nd row to last_row as shown below:

    header = spreadsheet.row(1)
    (2..spreadsheet.last_row).map do |i|
      row = Hash[[header, spreadsheet.row(i)].transpose]

      if your_condition
        //do something otherwise ignore the row
      end
    end

Hope it helps

Dusht
  • 4,712
  • 3
  • 18
  • 24