Class: Axlsx::Row

Inherits:
SimpleTypedList
  • Object
show all
Includes:
Accessors, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/row.rb

Overview

Note:

The recommended way to manage rows and cells is to use Worksheet#add_row

A Row is a single row in a worksheet.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Constructor Details

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

A new cell is created for each item in the values array. style and types options are applied as follows: If the types option is defined and is a symbol it is applied to all the cells created. If the types option is an array, cell types are applied by index for each cell If the types option is not set, the cell will automatically determine its type. If the style option is defined and is an Integer, it is applied to all cells created. If the style option is an array, style is applied by index for each cell. If the style option is not defined, the default style (0) is applied to each cell.

Parameters:

  • worksheet (Worksheet)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • values (Array)
  • types (Array, Symbol)
  • style (Array, Integer)
  • height (Float)

    the row's height (in points)

  • offset (Integer)
    • add empty columns before values

See Also:

  • #array_to_cells
  • Cell


31
32
33
34
35
36
37
# File 'lib/axlsx/workbook/worksheet/row.rb', line 31

def initialize(worksheet, values=[], options={})
  self.worksheet = worksheet
  super(Cell, nil, values.size + options[:offset].to_i)
  self.height = options.delete(:height)
  worksheet.rows << self
  array_to_cells(values, options)
end

Instance Attribute Details

#outline_levelInteger Also known as: outlineLevel

Outlining level of the row, when outlining is on

Returns:

  • (Integer)


57
58
59
# File 'lib/axlsx/workbook/worksheet/row.rb', line 57

def outline_level
  @outline_level
end

#sInteger

The style applied to the row. This affects the entire row.

Returns:

  • (Integer)


62
63
64
# File 'lib/axlsx/workbook/worksheet/row.rb', line 62

def s
  @s
end

#worksheetWorksheet

The worksheet this row belongs to

Returns:



47
48
49
# File 'lib/axlsx/workbook/worksheet/row.rb', line 47

def worksheet
  @worksheet
end

Instance Method Details

#add_cell(value = '', options = {}) ⇒ Cell

Adds a single cell to the row based on the data provided and updates the worksheet's autofit data.

Returns:



100
101
102
103
104
105
# File 'lib/axlsx/workbook/worksheet/row.rb', line 100

def add_cell(value = '', options = {})
  c = Cell.new(self, value, options)
  self << c
  worksheet.send(:update_column_info, self, [])
  c
end

#cellsObject

return cells



131
132
133
# File 'lib/axlsx/workbook/worksheet/row.rb', line 131

def cells
  self
end

#color=(color) ⇒ Object

sets the color for every cell in this row



108
109
110
111
112
# File 'lib/axlsx/workbook/worksheet/row.rb', line 108

def color=(color)
  each_with_index do | cell, index |
    cell.color = color.is_a?(Array) ? color[index] : color
  end
end

#heightFloat

Row height measured in point size. There is no margin padding on row height.

Returns:

  • (Float)


51
52
53
# File 'lib/axlsx/workbook/worksheet/row.rb', line 51

def height
  defined?(@ht) ? @ht : nil
end

#height=(v) ⇒ Object

See Also:



122
123
124
125
126
127
128
# File 'lib/axlsx/workbook/worksheet/row.rb', line 122

def height=(v)
  unless v.nil?
    Axlsx::validate_unsigned_numeric(v)
    @custom_height = true
    @ht = v
  end
end

#row_indexInteger

The index of this row in the worksheet

Returns:

  • (Integer)


81
82
83
# File 'lib/axlsx/workbook/worksheet/row.rb', line 81

def row_index
  worksheet.rows.index(self)
end

#style=(style) ⇒ Object

sets the style for every cell in this row



115
116
117
118
119
# File 'lib/axlsx/workbook/worksheet/row.rb', line 115

def style=(style)
  each_with_index do | cell, index |
    cell.style = style.is_a?(Array) ? style[index] : style
  end
end

#to_xml_string(r_index, str = '') ⇒ String

Serializes the row

Parameters:

  • r_index (Integer)

    The row index, 0 based.

  • str (String) (defaults to: '')

    The string this rows xml will be appended to.

Returns:

  • (String)


89
90
91
92
93
94
95
96
# File 'lib/axlsx/workbook/worksheet/row.rb', line 89

def to_xml_string(r_index, str = '')
  serialized_tag('row', str, :r => r_index + 1) do
    tmp = '' # time / memory tradeoff, lots of calls to rubyzip costs more
             # time..
    each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, tmp) }
    str << tmp
  end
end