Class: OoxmlParser::XlsxCell

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb

Overview

Single Cell of XLSX

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ XlsxCell

Returns a new instance of XlsxCell.



20
21
22
23
24
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 20

def initialize(parent: nil)
  @style_index = 0 # default style is zero
  @raw_text = ''
  super
end

Instance Attribute Details

#characterObject

Returns the value of attribute character.



7
8
9
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 7

def character
  @character
end

#formulaObject

Returns the value of attribute formula.



7
8
9
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 7

def formula
  @formula
end

#raw_textString

Returns text without applying any style modificators, like quote_prefix.

Returns:

  • (String)

    text without applying any style modificators, like quote_prefix



10
11
12
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 10

def raw_text
  @raw_text
end

#referenceString (readonly)

Returns An A-1 style reference to a cell.

Returns:

  • (String)

    An A-1 style reference to a cell.



16
17
18
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 16

def reference
  @reference
end

#style_indexInteger (readonly)

Returns index of style.

Returns:

  • (Integer)

    index of style



12
13
14
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 12

def style_index
  @style_index
end

#typeString (readonly)

Returns type of string.

Returns:

  • (String)

    type of string



18
19
20
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 18

def type
  @type
end

#valueString (readonly)

Returns value of cell.

Returns:

  • (String)

    value of cell



14
15
16
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 14

def value
  @value
end

Instance Method Details

#coordinatesCoordinates

Returns coordinates of cell.

Returns:



68
69
70
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 68

def coordinates
  @coordinates ||= Coordinates.new.parse_string(@reference)
end

#parse(node) ⇒ XlsxCell

Parse XlsxCell object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 29

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 's'
      @style_index = value.value.to_i
    when 't'
      @type = value.value.to_s
    when 'r'
      @reference = value.value.to_s
    end
  end
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'f'
      @formula = Formula.new(parent: self).parse(node_child)
    when 'v'
      @value = TextValue.new(parent: self).parse(node_child)
    end
  end
  parse_text_data
  self
end

#styleXf

Returns style of cell.

Returns:

  • (Xf)

    style of cell



53
54
55
56
57
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 53

def style
  return nil unless @style_index

  root_object.style_sheet.cell_xfs.xf_array[@style_index]
end

#textString

Returns text with modifiers.

Returns:

  • (String)

    text with modifiers



60
61
62
63
64
65
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 60

def text
  return '' unless @raw_text
  return @raw_text.dup.insert(0, "'") if style.quote_prefix

  @raw_text
end