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:



527
528
529
530
531
532
533
534
# File 'lib/spreadshoot.rb', line 527

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)


520
521
522
# File 'lib/spreadshoot.rb', line 520

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)


538
539
540
# File 'lib/spreadshoot.rb', line 538

def current_col
  @table.current_col
end

#current_rowFixnum

Zero-based index of the current row of the cell

Returns:

  • (Fixnum)


544
545
546
# File 'lib/spreadshoot.rb', line 544

def current_row
  @table.current_row
end

#output(xn_parent) ⇒ Object

Outputs the cell into the resulting xml



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/spreadshoot.rb', line 550

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)


578
579
580
# File 'lib/spreadshoot.rb', line 578

def to_s
  @coords
end