'how to get specific value cell index using rubyXL gem

I have a static header in my excel template and I want to find each column cell index using cell value.

Example:

Row1: cell1, cell2, cell3

I want to find the cell index which has a value [cell3].



Solution 1:[1]

It's possible to iterate over the cells and find the cell that equal some content

So as idea

def find_cell_by_content(worksheet, content)
  worksheet.each do |row|
    row.cells.each do |cell|
      return [cell.row, cell.column] if cell.value == content
    end
  end

  nil
end

This method will return row and column indices if such cell exists otherwise nil

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mechnicov