Class: OpenXml::Xlsx::Elements::Cell
- Inherits:
-
Object
- Object
- OpenXml::Xlsx::Elements::Cell
- Defined in:
- lib/openxml/xlsx/elements/cell.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #column_letter ⇒ Object
- #id ⇒ Object
-
#initialize(row, options = {}) ⇒ Cell
constructor
A new instance of Cell.
- #package ⇒ Object
- #to_xml(xml) ⇒ Object
- #workbook ⇒ Object
- #worksheet ⇒ Object
Constructor Details
#initialize(row, options = {}) ⇒ Cell
Returns a new instance of Cell.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 9 def initialize(row, ={}) @row = row @column = .fetch(:column) @value = [:value] case value when String @type = :string @string_id = package.string_ref(value) when Date then @type = :date @serial_date = to_serial_date(value) when Time then @type = :time @serial_time = to_serial_time(value) else @type = :general end @style = package.style_ref([:style]) if .key? :style @formula = [:formula] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def column @column end |
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def formula @formula end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def row @row end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def style @style end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 7 def value @value end |
Instance Method Details
#column_letter ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 34 def column_letter bytes = [] remaining = column while remaining > 0 bytes.unshift (remaining - 1) % 26 + 65 remaining = (remaining - 1) / 26 end bytes.pack "c*" end |
#id ⇒ Object
30 31 32 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 30 def id "#{column_letter}#{row.number}" end |
#package ⇒ Object
52 53 54 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 52 def package workbook.package end |
#to_xml(xml) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 56 def to_xml(xml) attributes = {"r" => id} attributes.merge!("s" => style) if style attributes.merge!("t" => "s") if type == :string value = self.value value = string_id if type == :string value = serial_date if type == :date value = serial_time if type == :time xml.c(attributes) do xml.f formula if formula xml.v value if value end end |
#workbook ⇒ Object
48 49 50 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 48 def workbook worksheet.workbook end |
#worksheet ⇒ Object
44 45 46 |
# File 'lib/openxml/xlsx/elements/cell.rb', line 44 def worksheet row.worksheet end |