Class: Axlsx::Row
- Inherits:
-
Object
- Object
- Axlsx::Row
- 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.
Constant Summary collapse
- SERIALIZABLE_ATTRIBUTES =
[:hidden, :outlineLevel, :collapsed, :style]
Instance Attribute Summary collapse
-
#cells ⇒ SimpleTypedList
readonly
The cells this row holds.
-
#collapsed ⇒ Boolean
Flag indicating if the outlining of the affected column(s) is in the collapsed state.
-
#height ⇒ Float
The height of this row in points, if set explicitly.
-
#hidden ⇒ Boolean
Flag indicating if the affected column(s) are hidden on this worksheet.
-
#outlineLevel ⇒ Integer
Outline level of affected column(s).
-
#style ⇒ Integer
Default style for the affected column(s).
-
#worksheet ⇒ Worksheet
readonly
The worksheet this row belongs to.
Instance Method Summary collapse
-
#add_cell(value = "", options = {}) ⇒ Cell
Adds a singel sell to the row based on the data provided and updates the worksheet’s autofit data.
-
#custom_height? ⇒ Boolean
true if the row height has been manually set.
-
#index ⇒ Integer
The index of this row in the worksheet.
-
#initialize(worksheet, values = [], options = {}) ⇒ Row
constructor
Creates a new 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.
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.
64 65 66 67 68 69 70 71 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 64 def initialize(worksheet, values=[], ={}) @height = 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
15 16 17 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 15 def cells @cells end |
#collapsed ⇒ Boolean
Flag indicating if the outlining of the affected column(s) is in the collapsed state.
23 24 25 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 23 def collapsed @collapsed end |
#height ⇒ Float
The height of this row in points, if set explicitly.
19 20 21 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 19 def height @height end |
#hidden ⇒ Boolean
Flag indicating if the affected column(s) are hidden on this worksheet.
27 28 29 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 27 def hidden @hidden end |
#outlineLevel ⇒ Integer
Outline level of affected column(s). Range is 0 to 7.
31 32 33 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 31 def outlineLevel @outlineLevel end |
#style ⇒ Integer
Default style for the affected column(s). Affects cells not yet allocated in the column(s). In other words, this style applies to new columns.
35 36 37 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 35 def style @style end |
#worksheet ⇒ Worksheet
The worksheet this row belongs to
11 12 13 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 11 def worksheet @worksheet end |
Instance Method Details
#add_cell(value = "", options = {}) ⇒ Cell
Adds a singel sell to the row based on the data provided and updates the worksheet’s autofit data.
119 120 121 122 123 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 119 def add_cell(value="", ={}) c = Cell.new(self, value, ) worksheet.send(:update_column_info, self.cells, [], self.cells.map(&:style)) c end |
#custom_height? ⇒ Boolean
true if the row height has been manually set
146 147 148 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 146 def custom_height? @height != nil end |
#index ⇒ Integer
The index of this row in the worksheet
94 95 96 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 94 def index worksheet.rows.index(self) end |
#to_ary ⇒ Array
returns the cells in this row as an array This lets us transpose the rows into columns
136 137 138 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 136 def to_ary @cells.to_ary end |
#to_xml_string(r_index, str = '') ⇒ String
Serializes the row
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 102 def to_xml_string(r_index, str = '') str << '<row r="' << (r_index + 1 ).to_s << '" ' instance_values.select { |key, value| SERIALIZABLE_ATTRIBUTES.include? key.to_sym }.each do |key, value| str << key << '="' << value.to_s << '" ' end if custom_height? str << 'customHeight="1" ht="' << height.to_s << '">' else str << '>' end @cells.each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) } str << '</row>' str end |