Module: RubyXL::LegacyCell

Included in:
Cell
Defined in:
lib/rubyXL/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formulaObject

Returns the value of attribute formula.



15
16
17
# File 'lib/rubyXL/cell.rb', line 15

def formula
  @formula
end

#worksheetObject

Returns the value of attribute worksheet.



15
16
17
# File 'lib/rubyXL/cell.rb', line 15

def worksheet
  @worksheet
end

Instance Method Details

#change_contents(data, formula_expression = nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rubyXL/cell.rb', line 99

def change_contents(data, formula_expression = nil)
  validate_worksheet

  if formula_expression then
    self.datatype = nil
    self.formula = RubyXL::Formula.new(:expression => formula_expression)
  else
    self.datatype = case data
                    when Date, Integer, Float then nil
                    else RubyXL::DataType::RAW_STRING
                    end
  end

  data = workbook.date_to_num(data) if data.is_a?(Date)

  self.raw_value = data
end

#change_fill(rgb = 'ffffff') ⇒ Object

changes fill color of cell



22
23
24
25
26
# File 'lib/rubyXL/cell.rb', line 22

def change_fill(rgb = 'ffffff')
  validate_worksheet
  Color.validate_color(rgb)
  self.style_index = workbook.modify_fill(self.style_index, rgb)
end

#change_font_bold(bolded = false) ⇒ Object

Changes font bold settings of cell



67
68
69
70
71
72
73
# File 'lib/rubyXL/cell.rb', line 67

def change_font_bold(bolded = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_bold(bolded)
  update_font_references(font)
end

#change_font_color(font_color = '000000') ⇒ Object

Changes font color of cell



48
49
50
51
52
53
54
55
# File 'lib/rubyXL/cell.rb', line 48

def change_font_color(font_color = '000000')
  validate_worksheet
  Color.validate_color(font_color)

  font = get_cell_font.dup
  font.set_rgb_color(font_color)
  update_font_references(font)
end

#change_font_italics(italicized = false) ⇒ Object

Changes font italics settings of cell



58
59
60
61
62
63
64
# File 'lib/rubyXL/cell.rb', line 58

def change_font_italics(italicized = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_italic(italicized)
  update_font_references(font)
end

#change_font_name(new_font_name = 'Verdana') ⇒ Object

Changes font name of cell



29
30
31
32
33
34
35
# File 'lib/rubyXL/cell.rb', line 29

def change_font_name(new_font_name = 'Verdana')
  validate_worksheet

  font = get_cell_font.dup
  font.set_name(new_font_name)
  update_font_references(font)
end

#change_font_size(font_size = 10) ⇒ Object

Changes font size of cell



38
39
40
41
42
43
44
45
# File 'lib/rubyXL/cell.rb', line 38

def change_font_size(font_size = 10)
  validate_worksheet
  raise 'Argument must be a number' unless font_size.is_a?(Integer) || font_size.is_a?(Float)

  font = get_cell_font.dup
  font.set_size(font_size)
  update_font_references(font)
end

#change_font_strikethrough(struckthrough = false) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/rubyXL/cell.rb', line 84

def change_font_strikethrough(struckthrough = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_strikethrough(struckthrough)
  update_font_references(font)
end

#change_font_underline(underlined = false) ⇒ Object

Changes font underline settings of cell



76
77
78
79
80
81
82
# File 'lib/rubyXL/cell.rb', line 76

def change_font_underline(underlined = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_underline(underlined)
  update_font_references(font)
end

#font_switch(change_type, arg) ⇒ Object

Performs correct modification based on what type of change_type is specified



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rubyXL/cell.rb', line 125

def font_switch(change_type, arg)
  case change_type
    when Worksheet::NAME          then change_font_name(arg)
    when Worksheet::SIZE          then change_font_size(arg)
    when Worksheet::COLOR         then change_font_color(arg)
    when Worksheet::ITALICS       then change_font_italics(arg)
    when Worksheet::BOLD          then change_font_bold(arg)
    when Worksheet::UNDERLINE     then change_font_underline(arg)
    when Worksheet::STRIKETHROUGH then change_font_strikethrough(arg)
    else raise 'Invalid change_type'
  end
end

#inspectObject



117
118
119
120
121
122
# File 'lib/rubyXL/cell.rb', line 117

def inspect
  str = "#<#{self.class}(#{row},#{column}): #{raw_value.inspect}"
  str += " =#{self.formula.expression}" if self.formula
  str += ", datatype = #{self.datatype}, style_index = #{self.style_index}>"
  return str
end

#workbookObject



17
18
19
# File 'lib/rubyXL/cell.rb', line 17

def workbook
  @worksheet.workbook
end