Class: Axlsx::Row
- Inherits:
-
Object
- Object
- 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
-
#cells ⇒ SimpleTypedList
readonly
The cells this row holds.
-
#outline_level ⇒ Integer
(also: #outlineLevel)
Outlining level of the row, when outlining is on.
-
#s ⇒ Integer
The style applied ot the row.
-
#worksheet ⇒ Worksheet
readonly
The worksheet this row belongs to.
Instance Method Summary collapse
-
#add_cell(value = "", options = {}) ⇒ Cell
Adds a single sell to the row based on the data provided and updates the worksheet's autofit data.
-
#height ⇒ Float
Row height measured in point size.
- #height=(v) ⇒ Object
-
#index ⇒ Integer
The index of this row in the worksheet.
-
#initialize(worksheet, values = [], options = {}) ⇒ Row
constructor
A new cell is created for each item in the values array.
-
#style=(style) ⇒ Object
sets the style for every cell in this row.
-
#to_ary ⇒ Array
returns the cells in this row as an array This lets us transpose the rows into columns.
-
#to_xml_string(r_index, str = '') ⇒ String
Serializes the row.
Methods included from SerializedAttributes
#declared_attributes, included, #serialized_attributes, #serialized_element_attributes
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.
30 31 32 33 34 35 36 37 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 30 def initialize(worksheet, values=[], ={}) @ht = nil self.worksheet = worksheet @cells = SimpleTypedList.new Cell @worksheet.rows << self self.height = .delete(:height) if [:height] array_to_cells(values, ) end |
Instance Attribute Details
#cells ⇒ SimpleTypedList (readonly)
The cells this row holds
51 52 53 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 51 def cells @cells end |
#outline_level ⇒ Integer Also known as: outlineLevel
Outlining level of the row, when outlining is on
61 62 63 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 61 def outline_level @outline_level end |
#s ⇒ Integer
The style applied ot the row. This affects the entire row.
66 67 68 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 66 def s @s end |
#worksheet ⇒ Worksheet
The worksheet this row belongs to
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 sell to the row based on the data provided and updates the worksheet's autofit data.
102 103 104 105 106 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 102 def add_cell(value="", ={}) c = Cell.new(self, value, ) worksheet.send(:update_column_info, self.cells, []) c end |
#height ⇒ Float
Row height measured in point size. There is no margin padding on row height.
55 56 57 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 55 def height @ht end |
#height=(v) ⇒ Object
124 125 126 127 128 129 130 131 |
# 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 ⇒ Integer
The index of this row in the worksheet
84 85 86 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 84 def index worksheet.rows.index(self) end |
#style=(style) ⇒ Object
sets the style for every cell in this row
109 110 111 112 113 114 |
# 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 ⇒ Array
returns the cells in this row as an array This lets us transpose the rows into columns
119 120 121 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 119 def to_ary @cells.to_ary end |
#to_xml_string(r_index, str = '') ⇒ String
Serializes the row
92 93 94 95 96 97 98 |
# 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 |