0

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].

1 Answers1

0

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

mechnicov
  • 12,025
  • 4
  • 33
  • 56