Class: RubyXL::Cell
Overview
Constant Summary
collapse
- NUMBER_REGEXP =
/\A-?\d+((?:\.\d+)?(?:e[+-]?\d+)?)?\Z/i
Instance Attribute Summary
Attributes included from LegacyCell
#formula, #worksheet
#local_namespaces
Instance Method Summary
collapse
#change_border, #change_border_color, #change_contents, #change_fill, #change_font_bold, #change_font_color, #change_font_italics, #change_font_name, #change_font_size, #change_font_strikethrough, #change_font_underline, #change_horizontal_alignment, #change_text_indent, #change_text_rotation, #change_text_wrap, #change_vertical_alignment, #fill_color, #font_color, #font_name, #font_size, #font_switch, #get_border, #get_border_color, #horizontal_alignment, #is_bolded, #is_italicized, #is_struckthrough, #is_underlined, #set_number_format, #text_indent, #text_rotation, #text_wrap, #vertical_alignment
Methods included from LegacyCell
#workbook
#==, #before_write_xml, included, #initialize, #write_xml
Instance Method Details
#column ⇒ Object
48
49
50
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 48
def column
r && r.first_col
end
|
#column=(v) ⇒ Object
52
53
54
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 52
def column=(v)
self.r = RubyXL::Reference.new(row || 0, v)
end
|
#index_in_collection ⇒ Object
36
37
38
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 36
def index_in_collection
r.col_range.begin
end
|
#inspect ⇒ Object
95
96
97
98
99
100
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 95
def inspect
str = "#<#{self.class}(#{row},#{column}): #{raw_value.inspect}"
str += " =#{self.formula.expression}" if self.formula
str += ", datatype=#{self.datatype.inspect}, style_index=#{self.style_index.inspect}>"
return str
end
|
#is_date? ⇒ Boolean
69
70
71
72
73
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 69
def is_date?
return false unless raw_value =~ NUMBER_REGEXP num_fmt = self.number_format
num_fmt && num_fmt.is_date_format?
end
|
65
66
67
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 65
def number_format
workbook.stylesheet.get_number_format_by_id(get_cell_xf.num_fmt_id)
end
|
#raw_value ⇒ Object
56
57
58
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 56
def raw_value
value_container && value_container.value
end
|
#raw_value=(v) ⇒ Object
60
61
62
63
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 60
def raw_value=(v)
self.value_container ||= RubyXL::CellValue.new
value_container.value = v
end
|
#row ⇒ Object
40
41
42
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 40
def row
r && r.first_row
end
|
#row=(v) ⇒ Object
44
45
46
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 44
def row=(v)
self.r = RubyXL::Reference.new(v, column || 0)
end
|
#value(args = {}) ⇒ Object
Gets massaged value of the cell, converting datatypes to those known to Ruby (that includes stripping any special formatting from RichText).
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/rubyXL/objects/sheet_data.rb', line 77
def value(args = {})
r = self.raw_value
case datatype
when RubyXL::DataType::SHARED_STRING then workbook.shared_strings_container[r.to_i].to_s
when RubyXL::DataType::INLINE_STRING then is.to_s
when RubyXL::DataType::RAW_STRING then raw_value
else
if is_date? then workbook.num_to_date(r.to_f)
elsif r.is_a?(String) && (r =~ NUMBER_REGEXP) then if $1 != '' then r.to_f
else r.to_i
end
else r
end
end
end
|