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.
Instance Attribute Summary collapse
-
#cells ⇒ SimpleTypedList
readonly
The cells this row holds.
-
#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.
-
#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(xml) ⇒ 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.
29 30 31 32 33 34 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 29 def initialize(worksheet, values=[], ={}) self.worksheet = worksheet @cells = SimpleTypedList.new Cell @worksheet.rows << self array_to_cells(values, ) end |
Instance Attribute Details
#cells ⇒ SimpleTypedList (readonly)
The cells this row holds
13 14 15 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 13 def cells @cells end |
#worksheet ⇒ Worksheet
The worksheet this row belongs to
9 10 11 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 9 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.
51 52 53 54 55 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 51 def add_cell(value="", ={}) c = Cell.new(self, value, ) update_auto_fit_data c end |
#index ⇒ Integer
The index of this row in the worksheet
38 39 40 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 38 def index worksheet.rows.index(self) end |
#style=(style) ⇒ Object
sets the style for every cell in this row
58 59 60 61 62 63 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 58 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
68 69 70 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 68 def to_ary @cells.to_ary end |
#to_xml(xml) ⇒ String
Serializes the row
45 46 47 |
# File 'lib/axlsx/workbook/worksheet/row.rb', line 45 def to_xml(xml) xml.row(:r => index+1) { @cells.each { |cell| cell.to_xml(xml) } } end |