class Axlsx::Row

A Row is a single row in a worksheet. @note The recommended way to manage rows and cells is to use Worksheet#add_row @see Worksheet#add_row

Attributes

cells[R]

The cells this row holds @return [SimpleTypedList]

outlineLevel[R]

Outlining level of the row, when outlining is on @return [Integer]

outline_level[R]

Outlining level of the row, when outlining is on @return [Integer]

s[R]

The style applied ot the row. This affects the entire row. @return [Integer]

worksheet[R]

The worksheet this row belongs to @return [Worksheet]

Public Class Methods

new(worksheet, values=[], options={}) click to toggle source

Creates a new row. New Cell objects are created based on the values, types and style options. 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.

@param [Worksheet] worksheet @option options [Array] values @option options [Array, Symbol] types @option options [Array, Integer] style @option options [Float] height the row’s height (in points) @see Row#array_to_cells @see Cell

# File lib/axlsx/workbook/worksheet/row.rb, line 30
def initialize(worksheet, values=[], options={})
  @ht = nil
  self.worksheet = worksheet
  @cells = SimpleTypedList.new Cell
  @worksheet.rows << self
  self.height = options.delete(:height) if options[:height]
  array_to_cells(values, options)
end

Public Instance Methods

add_cell(value="", options={}) click to toggle source

Adds a single sell to the row based on the data provided and updates the worksheet’s autofit data. @return [Cell]

# File lib/axlsx/workbook/worksheet/row.rb, line 102
def add_cell(value="", options={})
  c = Cell.new(self, value, options)
  worksheet.send(:update_column_info, self.cells, [])
  c
end
height() click to toggle source

Row height measured in point size. There is no margin padding on row height. @return [Float]

# File lib/axlsx/workbook/worksheet/row.rb, line 55
def height
  @ht
end
height=(v) click to toggle source

@see height

# File lib/axlsx/workbook/worksheet/row.rb, line 124
def height=(v)
  Axlsx::validate_unsigned_numeric(v)
  unless v.nil?
    @ht = v
    @custom_height = true
  end
  @ht
end
index() click to toggle source

The index of this row in the worksheet @return [Integer]

# File lib/axlsx/workbook/worksheet/row.rb, line 84
def index
  worksheet.rows.index(self)
end
outlineLevel=(v)
Alias for: outline_level=
outline_level=(v) click to toggle source

@see Row#outline

# File lib/axlsx/workbook/worksheet/row.rb, line 76
def outline_level=(v)
  Axlsx.validate_unsigned_numeric(v)
  @outline_level = v
end
Also aliased as: outlineLevel=
s=(v) click to toggle source

@see Row#s

# File lib/axlsx/workbook/worksheet/row.rb, line 69
def s=(v)
  Axlsx.validate_unsigned_numeric(v)
  @custom_format = true 
  @s = v
end
style=(style) click to toggle source

sets the style for every cell in this row

# File lib/axlsx/workbook/worksheet/row.rb, line 109
def style=(style)
  cells.each_with_index do | cell, index |
    s = style.is_a?(Array) ? style[index] : style
    cell.style = s
  end
end
to_ary() click to toggle source

returns the cells in this row as an array This lets us transpose the rows into columns @return [Array]

# File lib/axlsx/workbook/worksheet/row.rb, line 119
def to_ary
  @cells.to_ary
end
to_xml_string(r_index, str = '') click to toggle source

Serializes the row @param [Integer] r_index The row index, 0 based. @param [String] str The string this rows xml will be appended to. @return [String]

# File lib/axlsx/workbook/worksheet/row.rb, line 92
def to_xml_string(r_index, str = '')
  str << '<row '
  serialized_attributes(str, { :r => r_index + 1 })
  str << '>'
  @cells.each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
  str << '</row>'
end

Private Instance Methods

array_to_cells(values, options={}) click to toggle source

Converts values, types, and style options into cells and associates them with this row. A new cell is created for each item in the values array. If value option is defined and is a symbol it is applied to all the cells created. If the value option is an array, cell types are applied by index for each cell 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. @option options [Array] values @option options [Array, Symbol] types @option options [Array, Integer] style

# File lib/axlsx/workbook/worksheet/row.rb, line 147
def array_to_cells(values, options={})
  values = values
  DataTypeValidator.validate 'Row.array_to_cells', Array, values
  types, style, formula_values = options.delete(:types), options.delete(:style), options.delete(:formula_values)
  values.each_with_index do |value, index|

    #WTF IS THIS PAP?
    cell_style = style.is_a?(Array) ? style[index] : style
    options[:style] = cell_style if cell_style

    cell_type = types.is_a?(Array)? types[index] : types
    options[:type] = cell_type if cell_type

    formula_value = formula_values[index] if formula_values.is_a?(Array)
    options[:formula_value] = formula_value if formula_value

    Cell.new(self, value, options)

    options.delete(:style)
    options.delete(:type)
    options.delete(:formula_value)
  end
end
worksheet=(v) click to toggle source

assigns the owning worksheet for this row

# File lib/axlsx/workbook/worksheet/row.rb, line 136
def worksheet=(v) DataTypeValidator.validate "Row.worksheet", Worksheet, v; @worksheet=v; end