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
Outlining level of the row, when outlining is on @return [Integer]
Outlining level of the row, when outlining is on @return [Integer]
The style applied ot the row. This affects the entire row. @return [Integer]
The worksheet this row belongs to @return [Worksheet]
Public Class Methods
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) @option options [Integer] offset - add empty columns before values @see Row#array_to_cells
@see Cell
Axlsx::SimpleTypedList::new
# 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
Public Instance Methods
Adds a single cell 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 100 def add_cell(value = '', options = {}) c = Cell.new(self, value, options) self << c worksheet.send(:update_column_info, self, []) c end
return cells
# File lib/axlsx/workbook/worksheet/row.rb, line 131 def cells self end
sets the color for every cell in this row
# 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
Row
height measured in point size. There is no margin padding on row height. @return [Float]
# File lib/axlsx/workbook/worksheet/row.rb, line 51 def height defined?(@ht) ? @ht : nil end
@see height
# 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
@see Row#outline
# File lib/axlsx/workbook/worksheet/row.rb, line 72 def outline_level=(v) Axlsx.validate_unsigned_numeric(v) @outline_level = v end
The index of this row in the worksheet @return [Integer]
# File lib/axlsx/workbook/worksheet/row.rb, line 81 def row_index worksheet.rows.index(self) end
@see Row#s
# File lib/axlsx/workbook/worksheet/row.rb, line 65 def s=(v) Axlsx.validate_unsigned_numeric(v) @custom_format = true @s = v end
sets the style for every cell in this row
# 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
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 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
Private Instance Methods
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 149 def array_to_cells(values, options={}) DataTypeValidator.validate :array_to_cells, Array, values types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset) offset.to_i.times { |index| self[index] = Cell.new(self) } if offset values.each_with_index do |value, index| options[:style] = style.is_a?(Array) ? style[index] : style if style options[:type] = types.is_a?(Array) ? types[index] : types if types options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas if escape_formulas options[:formula_value] = formula_values[index] if formula_values.is_a?(Array) self[index + offset.to_i] = Cell.new(self, value, options) end end
assigns the owning worksheet for this row
# File lib/axlsx/workbook/worksheet/row.rb, line 138 def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet=v; end