Class: Excel::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = {}) ⇒ Column

Define identifier and optional other values.

*title: Used for title line. Default: ID



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rexcel/column.rb', line 8

def initialize( id, options = {})
  @id = id
  @title = id
  options.each{|key, value|
    case key
      when :title; @title = value.respond_to?(:encode) ? value.encode('utf-8') : value
      when :width
        if value.is_a?(Numeric)
          @width = value
        elsif value.respond_to?(:to_i)
          @width = value.to_i
        else
          raise ArgumentError, "Width is no Numeric"
        end
        raise ArgumentError, "Length zero or less" if @width <= 0
      when :style
        raise ArgumentError unless value.is_a?(Style)
        @style = value
      else
        @log.error("#{self.class}: Undefined option #{key}")
    end
  }
end

Instance Attribute Details

#idObject (readonly)

Identifier of column. Used for ruby internal reference



32
33
34
# File 'lib/rexcel/column.rb', line 32

def id
  @id
end

#titleObject (readonly)

Used for title line in Excel



34
35
36
# File 'lib/rexcel/column.rb', line 34

def title
  @title
end

Instance Method Details

#to_xlsObject

Fill an Excel Columns Receives a OLE-cell and optional a row.



57
58
59
# File 'lib/rexcel/column.rb', line 57

def to_xls()
  @log.fatal("Not implemented yet")    
end

#to_xml(xmlbuilder, ns) ⇒ Object

Build the xml a work sheet column.

ns must be a method-object to implement the namespace definitions.

Format options (bold, italic, colors) are forwarded to cells.



43
44
45
46
47
48
49
# File 'lib/rexcel/column.rb', line 43

def to_xml(xmlbuilder, ns)  
  options = {}
  options[ns.call('Width')] = @width if @width
  options[ns.call('StyleID')] = @style.style_id if @style
  
  xmlbuilder[ns.call].Column( options )
end