Class: XLSX::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsx/cell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_number, col_number, value) ⇒ Cell

Returns a new instance of Cell.



30
31
32
33
34
# File 'lib/xlsx/cell.rb', line 30

def initialize(row_number, col_number, value)
  @row_number = row_number
  @col_number = col_number
  @value = value
end

Instance Attribute Details

#col_numberObject (readonly)

Returns the value of attribute col_number.



27
28
29
# File 'lib/xlsx/cell.rb', line 27

def col_number
  @col_number
end

#row_numberObject (readonly)

Returns the value of attribute row_number.



26
27
28
# File 'lib/xlsx/cell.rb', line 26

def row_number
  @row_number
end

#valueObject

Returns the value of attribute value.



28
29
30
# File 'lib/xlsx/cell.rb', line 28

def value
  @value
end

Class Method Details

.cell_name(row_number, col_number) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xlsx/cell.rb', line 40

def self.cell_name(row_number, col_number)
  raise "Column #{col_number} out of range" if col_number > 701
  
  if col_number <= 25
    col_name = ''
  else
    c = col_number / 26
    col_name = (?A.ord + c - 1).chr
    col_number = col_number % 26
  end
  col_name += (?A.ord + col_number).chr
  "#{col_name}#{row_number + 1}"
end

Instance Method Details

#nameObject



36
37
38
# File 'lib/xlsx/cell.rb', line 36

def name
  XLSX::Cell.cell_name(@row_number, @col_number)
end