Class: Spreadshoot::Cell

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

Overview

A cell within a row.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, value, options = {}) ⇒ Cell

Note:

Do not use directly, use Row#cell to create a cell.

Returns a new instance of Cell.

See Also:



541
542
543
544
545
546
547
548
# File 'lib/spreadshoot.rb', line 541

def initialize table, value, options = {}
  @table = table
  @value = value
  @options = options
  @coords = @table.coords
  @table.worksheet.set_col_width(@table.current_col, @options[:width]) if @options.has_key?(:width)
  @options[:format] ||= :date if @value.is_a?(Date) || @value.is_a?(Time)
end

Class Method Details

.alpha_index(i) ⇒ String

maps numeric column indices to letter based: 0 -> ‘A’, 1 -> ‘B’, 26 -> ‘AA’ and so on

Returns:

  • (String)


534
535
536
# File 'lib/spreadshoot.rb', line 534

def self.alpha_index i
  @alpha_indices[i]
end

Instance Method Details

#current_colFixnum

Zero-based index of the current column of the cell

Returns:

  • (Fixnum)


552
553
554
# File 'lib/spreadshoot.rb', line 552

def current_col
  @table.current_col
end

#current_rowFixnum

Zero-based index of the current row of the cell

Returns:

  • (Fixnum)


558
559
560
# File 'lib/spreadshoot.rb', line 558

def current_row
  @table.current_row
end

#output(xn_parent) ⇒ Object

Outputs the cell into the resulting xml



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/spreadshoot.rb', line 564

def output xn_parent
  r = {:r => @coords}
  @options = @value if @value.is_a?(Hash)
  if style = @table.worksheet.spreadsheet.style(@options)
    r.merge!(:s => style + 1)
  end
  case @value
  when String
    i = @table.worksheet.spreadsheet.ss_index(@value)
    xn_parent.c(r.merge(:t => 's')){ |xc| xc.v(i) }
  when Hash # no @value, formula in options
    xn_parent.c(r) do |xc|
      xc.f(@options[:formula])
    end
  when Date
    xn_parent.c(r){|xc| xc.v((@value - Date.new(1899,12,30)).to_i)}
  when Time
    xn_parent.c(r){|xc| xc.v((@value - Time.new(1899,12,30)) / (24*60*60))}
  when nil
    xn_parent.c(r)
  else
    xn_parent.c(r){ |xc| xc.v(@value) }
  end
end

#to_sString

Outputs cell coordinates (e.g. “C3”, “AG41” and so on)

Returns:

  • (String)


592
593
594
# File 'lib/spreadshoot.rb', line 592

def to_s
  @coords
end