Class: OpenXml::Xlsx::Elements::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/openxml/xlsx/elements/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet, options = {}) ⇒ Row

Returns a new instance of Row.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openxml/xlsx/elements/row.rb', line 7

def initialize(worksheet, options={})
  @worksheet = worksheet
  @number = options.fetch(:number)
  @height = options[:height]
  @hidden = options[:hidden]
  @cells = []

  Array(options[:cells]).each do |attributes|
    add_cell attributes
  end
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells.



5
6
7
# File 'lib/openxml/xlsx/elements/row.rb', line 5

def cells
  @cells
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/openxml/xlsx/elements/row.rb', line 5

def height
  @height
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



5
6
7
# File 'lib/openxml/xlsx/elements/row.rb', line 5

def hidden
  @hidden
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/openxml/xlsx/elements/row.rb', line 5

def number
  @number
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



5
6
7
# File 'lib/openxml/xlsx/elements/row.rb', line 5

def worksheet
  @worksheet
end

Instance Method Details

#add_cell(attributes) ⇒ Object



19
20
21
# File 'lib/openxml/xlsx/elements/row.rb', line 19

def add_cell(attributes)
  cells.push Xlsx::Elements::Cell.new(self, attributes)
end

#to_xml(xml) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/openxml/xlsx/elements/row.rb', line 23

def to_xml(xml)
  attributes = {"r" => number}
  attributes.merge!("ht" => height, "customHeight" => 1) if height
  attributes.merge!("hidden" => 1) if hidden
  xml.row(attributes) do
    cells.each do |cell|
      cell.to_xml(xml)
    end
  end
end