Class: Axlsx::Row
- Inherits:
-
SimpleTypedList
- Object
- Array
- SimpleTypedList
- Axlsx::Row
- Includes:
- Accessors, SerializedAttributes
- Defined in:
- lib/axlsx/workbook/worksheet/row.rb
Overview
The recommended way to manage rows and cells is to use Worksheet#add_row
A Row is a single row in a worksheet.
Instance Attribute Summary collapse
-
#outline_level ⇒ Integer
(also: #outlineLevel)
Outlining level of the row, when outlining is on.
-
#s ⇒ Integer
The style applied to the row.
-
#worksheet ⇒ Worksheet
readonly
The worksheet this row belongs to.
Instance Method Summary collapse
-
#add_cell(value = '', options = {}) ⇒ Cell
Adds a single cell to the row based on the data provided and updates the worksheet's autofit data.
-
#cells ⇒ Object
return cells.
-
#color=(color) ⇒ Object
Sets the color for every cell in this row.
-
#escape_formulas=(value) ⇒ Object
Sets escape_formulas for every cell in this row.
-
#height ⇒ Float
Row height measured in point size.
- #height=(v) ⇒ Object
-
#initialize(worksheet, values = [], options = {}) ⇒ Row
constructor
Creates a new row.
-
#row_index ⇒ Integer
The index of this row in the worksheet.
-
#style=(style) ⇒ Object
Sets the style for every cell in this row.
-
#to_xml_string(r_index, str = +'')) ⇒ String
Serializes the row.
Methods included from SerializedAttributes
included, #serialized_attributes, #serialized_element_attributes, #serialized_tag
Constructor Details
#initialize(worksheet, values = [], options = {}) ⇒ Row
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.
33 34 35 36 37 38 39 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 33 def initialize(worksheet, values = [], = {}) self.worksheet = worksheet super(Cell, nil, values.size + [:offset].to_i) self.height = .delete(:height) worksheet.rows << self array_to_cells(values, ) end |
Instance Attribute Details
#outline_level ⇒ Integer Also known as: outlineLevel
Outlining level of the row, when outlining is on
59 60 61 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 59 def outline_level @outline_level end |
#s ⇒ Integer
The style applied to the row. This affects the entire row.
64 65 66 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 64 def s @s end |
#worksheet ⇒ Worksheet
The worksheet this row belongs to
49 50 51 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 49 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.
99 100 101 102 103 104 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 99 def add_cell(value = '', = {}) c = Cell.new(self, value, ) self << c worksheet.send(:update_column_info, self, []) c end |
#cells ⇒ Object
return cells
139 140 141 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 139 def cells self end |
#color=(color) ⇒ Object
Sets the color for every cell in this row.
107 108 109 110 111 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 107 def color=(color) each_with_index do |cell, index| cell.color = color.is_a?(Array) ? color[index] : color end end |
#escape_formulas=(value) ⇒ Object
Sets escape_formulas for every cell in this row. This determines whether to treat values starting with an equals sign as formulas or as literal strings.
123 124 125 126 127 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 123 def escape_formulas=(value) each_with_index do |cell, index| cell.escape_formulas = value.is_a?(Array) ? value[index] : value end end |
#height ⇒ Float
Row height measured in point size. There is no margin padding on row height.
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 53 def height defined?(@ht) ? @ht : nil end |
#height=(v) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 130 def height=(v) unless v.nil? Axlsx.validate_unsigned_numeric(v) @custom_height = true @ht = v end end |
#row_index ⇒ Integer
The index of this row in the worksheet
83 84 85 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 83 def row_index worksheet.rows.index(self) end |
#style=(style) ⇒ Object
Sets the style for every cell in this row.
114 115 116 117 118 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 114 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
91 92 93 94 95 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 91 def to_xml_string(r_index, str = +'') serialized_tag('row', str, r: Axlsx.row_ref(r_index)) do each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) } end end |