Class: OoxmlParser::XlsxRow

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

Overview

Single Row 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) ⇒ XlsxRow

Returns a new instance of XlsxRow.



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

def initialize(parent: nil)
  @cells_raw = []
  @cells = []
  super
end

Instance Attribute Details

#cells_rawArray<Cells> (readonly)

Returns cells of row, as in xml structure.

Returns:

  • (Array<Cells>)

    cells of row, as in xml structure



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

def cells_raw
  @cells_raw
end

#custom_heightTrue, False

Returns true if the row height has been manually set.

Returns:

  • (True, False)

    true if the row height has been manually set.



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

def custom_height
  @custom_height
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#hiddenObject

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#indexInteger

Returns Indicates to which row in the sheet this <row> definition corresponds.

Returns:

  • (Integer)

    Indicates to which row in the sheet this <row> definition corresponds.



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

def index
  @index
end

#style_indexInteger (readonly)

Returns index of style of row.

Returns:

  • (Integer)

    index of style of row



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

def style_index
  @style_index
end

Instance Method Details

#cellsArray<XlsxCell, nil>

Returns list of cell in row, with nil, if cell data is not stored in xml.

Returns:

  • (Array<XlsxCell, nil>)

    list of cell in row, with nil, if cell data is not stored in xml



53
54
55
56
57
58
59
60
61
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row.rb', line 53

def cells
  return @cells if @cells.any?

  cells_raw.each do |cell|
    @cells[cell.coordinates.column_number.to_i - 1] = cell
  end

  @cells
end

#parse(node) ⇒ XlsxRow

Parse XlsxRow object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



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

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'customHeight'
      @custom_height = option_enabled?(node, 'customHeight')
    when 'ht'
      @height = OoxmlSize.new(value.value.to_f, :point)
    when 'hidden'
      @hidden = option_enabled?(node, 'hidden')
    when 'r'
      @index = value.value.to_i
    when 's'
      @style_index = value.value.to_i
    end
  end
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'c'
      @cells_raw << XlsxCell.new(parent: self).parse(node_child)
    end
  end
  self
end

#styleXf?

Returns style of row or ‘nil` if not applied.

Returns:

  • (Xf, nil)

    style of row or ‘nil` if not applied



64
65
66
67
68
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row.rb', line 64

def style
  return nil unless @style_index

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