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

#fill_colorObject

returns cell’s fill color



155
156
157
158
# File 'lib/rubyXL/cell.rb', line 155

def fill_color()
  validate_worksheet
  return workbook.get_fill_color(get_cell_xf)
end

#font_colorObject



149
150
151
152
# File 'lib/rubyXL/cell.rb', line 149

def font_color()
  validate_worksheet
  get_cell_font.get_rgb_color || '000000'
end

#font_nameObject



139
140
141
142
# File 'lib/rubyXL/cell.rb', line 139

def font_name()
  validate_worksheet
  get_cell_font.get_name
end

#font_sizeObject



144
145
146
147
# File 'lib/rubyXL/cell.rb', line 144

def font_size()
  validate_worksheet
  get_cell_font.get_size
end

#font_switch(change_type, arg) ⇒ Object

Performs correct modification based on what type of change_type is specified



192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/rubyXL/cell.rb', line 192

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

#horizontal_alignmentObject

returns cell’s horizontal alignment



161
162
163
164
165
166
# File 'lib/rubyXL/cell.rb', line 161

def horizontal_alignment()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.horizontal
end

#inspectObject



184
185
186
187
188
189
# File 'lib/rubyXL/cell.rb', line 184

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

#is_boldedObject

returns if font is bolded



124
125
126
127
# File 'lib/rubyXL/cell.rb', line 124

def is_bolded()
  validate_worksheet
  get_cell_font.is_bold
end

#is_italicizedObject

returns if font is italicized



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

def is_italicized()
  validate_worksheet
  get_cell_font.is_italic
end

#is_struckthroughObject



134
135
136
137
# File 'lib/rubyXL/cell.rb', line 134

def is_struckthrough()
  validate_worksheet
  get_cell_font.is_strikethrough
end

#is_underlinedObject



129
130
131
132
# File 'lib/rubyXL/cell.rb', line 129

def is_underlined()
  validate_worksheet
  get_cell_font.is_underlined
end

#text_wrapObject

returns cell’s wrap



177
178
179
180
181
182
# File 'lib/rubyXL/cell.rb', line 177

def text_wrap()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.wrap_text
end

#vertical_alignmentObject

returns cell’s vertical alignment



169
170
171
172
173
174
# File 'lib/rubyXL/cell.rb', line 169

def vertical_alignment()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.vertical
end

#workbookObject



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

def workbook
  @worksheet.workbook
end