Module: Oxcelix::Cellhelper

Included in:
Cell, Sheet, Workbook
Defined in:
lib/oxcelix/cellhelper.rb

Overview

The Cellhelper module defines some methods useful to manipulate Cell objects

Instance Method Summary collapse

Instance Method Details

#x(coord = nil) ⇒ Integer

When called without parameters, returns the x coordinate of the calling cell object based on the value of #@xlcoords If a parameter is given, #x will return the x coordinate corresponding to the parameter

Examples:

find x coordinate (column number) of a cell

c = Cell.new
c.xlcoords = ('B3')
c.x #=> 1

27
28
29
30
31
32
# File 'lib/oxcelix/cellhelper.rb', line 27

def x(coord=nil)
  if coord.nil?
    coord = @xlcoords
  end
  ('A'..(coord.scan(/\p{Alpha}+|\p{Digit}+/u)[0])).to_a.length-1
end

#y(coord = nil) ⇒ Integer

When called without parameters, returns the y coordinate of the calling cell object based on the value of #@xlcoords If a parameter is given, #y will return the y coordinate corresponding to the parameter

Examples:

find y coordinate (row number) of a cell

c = Cell.new
c.xlcoords = ('B3')
c.y #=> 2

42
43
44
45
46
47
# File 'lib/oxcelix/cellhelper.rb', line 42

def y(coord=nil)
  if coord.nil?
    coord = @xlcoords
  end
  coord.scan(/\p{Alpha}+|\p{Digit}+/u)[1].to_i-1
end