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 =
Note:
height(ht) and customHeight are manages separately for now. Have a look at Row#height
A list of serilizable attributes.
[:hidden, :outlineLevel, :collapsed, :s, :customFormat, :ph]
Instance Attribute Summary collapse
-
#cells ⇒ SimpleTypedList
readonly
The cells this row holds.
-
#collapsed ⇒ Boolean
Flag indicating if the outlining of row.
-
#customFormat ⇒ Boolean
readonly
indicates that a style has been applied directly to the row via Row#s.
-
#height ⇒ Float
Row height measured in point size.
-
#hidden ⇒ Boolean
Flag indicating if the the row is hidden.
-
#outlineLevel ⇒ Integer
Outlining level of the row, when outlining is on.
-
#ph ⇒ Boolean
indicates if the row should show phonetic.
-
#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 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.
-
#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.
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.
75 76 77 78 79 80 81 82 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 75 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
24 25 26 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 24 def cells @cells end |
#collapsed ⇒ Boolean
Flag indicating if the outlining of row.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 32 def collapsed @collapsed end |
#customFormat ⇒ Boolean (readonly)
indicates that a style has been applied directly to the row via Row#s
48 49 50 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 48 def customFormat @customFormat end |
#height ⇒ Float
Row height measured in point size. There is no margin padding on row height.
28 29 30 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 28 def height @height end |
#hidden ⇒ Boolean
Flag indicating if the the row is hidden.
36 37 38 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 36 def hidden @hidden end |
#outlineLevel ⇒ Integer
Outlining level of the row, when outlining is on
40 41 42 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 40 def outlineLevel @outlineLevel end |
#ph ⇒ Boolean
indicates if the row should show phonetic
52 53 54 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 52 def ph @ph end |
#s ⇒ Integer
The style applied ot the row. This affects the entire row.
44 45 46 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 44 def s @s end |
#worksheet ⇒ Worksheet
The worksheet this row belongs to
20 21 22 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 20 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.
135 136 137 138 139 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 135 def add_cell(value="", ={}) c = Cell.new(self, value, ) worksheet.send(:update_column_info, self.cells, []) c end |
#custom_height? ⇒ Boolean
true if the row height has been manually set
162 163 164 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 162 def custom_height? @height != nil end |
#index ⇒ Integer
The index of this row in the worksheet
110 111 112 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 110 def index worksheet.rows.index(self) end |
#style=(style) ⇒ Object
sets the style for every cell in this row
142 143 144 145 146 147 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 142 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
152 153 154 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 152 def to_ary @cells.to_ary end |
#to_xml_string(r_index, str = '') ⇒ String
Serializes the row
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 118 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 |