Class: Rspreadsheet::Row
- Inherits:
-
XMLTiedItem
- Object
- XMLTied
- XMLTiedItem
- Rspreadsheet::Row
- Defined in:
- lib/rspreadsheet/row.rb
Overview
Represents a row in a spreadsheet which has coordinates, contains value, formula and can be formated. You can get this object like this (suppose that @worksheet contains Worksheet object)
@row = @worksheet.row(5)
Mostly you will this object to access values of cells in the row
@row[2] # identical to @worksheet[5,2] or @row.cells(2).value
or directly row Cell
objects
@row.cell(2) # => identical to @worksheet.rows(5).cells(2)
You can use it to manipulate rows
@row.add_row_above # adds empty row above
@row.delete # deletes row
and shifts all other rows down/up appropriatelly.
XMLTiedArray_WithRepeatableItems related methods collapse
-
#rowi ⇒ Integer
readonly
Row index of the row.
-
#worksheet ⇒ Worksheet
readonly
Worksheet which contains the row.
XMLTiedArray_WithRepeatableItems related methods collapse
-
#initialize(aworksheet, arowi) ⇒ Row
constructor
A new instance of Row.
- #prepare_subitem(coli) ⇒ Object
- #subnode_options ⇒ Object
Syntactic sugar collapse
-
#[](coli) ⇒ String or Float or Date
returns value of the cell at column
coli
. -
#[]=(coli, avalue) ⇒ Object
sets value of cell in column
coli
. - #cells(*params) ⇒ Object (also: #cell)
-
#cellvalues ⇒ Array
return array of cell values .
-
#cellvalues=(avalue) ⇒ Object
sets values of cells of row to values from
avalue
.
Other methods collapse
-
#add_row_above ⇒ Object
(also: #insert_row_above)
Inserts row above itself (and shifts itself and all following rows down).
- #clone_above_row(target_rowi) ⇒ Object
- #next_row ⇒ Object (also: #next)
- #nonemptycells ⇒ Object
- #nonemptycellsindexes ⇒ Object
- #relative(rowi_offset) ⇒ Object
- #style_name=(value) ⇒ Object
Constructor Details
#initialize(aworksheet, arowi) ⇒ Row
Returns a new instance of Row.
43 44 45 46 |
# File 'lib/rspreadsheet/row.rb', line 43 def initialize(aworksheet,arowi) initialize_xml_tied_array initialize_xml_tied_item(aworksheet,arowi) end |
Instance Attribute Details
#rowi ⇒ Integer (readonly)
Returns row index of the row.
41 |
# File 'lib/rspreadsheet/row.rb', line 41 def rowi; index end |
#worksheet ⇒ Worksheet (readonly)
Returns worksheet which contains the row.
38 |
# File 'lib/rspreadsheet/row.rb', line 38 def worksheet; parent end |
Instance Method Details
#[](coli) ⇒ String or Float or Date
returns value of the cell at column coli
.
@row = @worksheet.rows(5) # with cells containing names of months
@row[1] # => "January"
@row.cells(2).value # => "February"
@row[1].class # => String
66 |
# File 'lib/rspreadsheet/row.rb', line 66 def [](coli); cells(coli).value end |
#[]=(coli, avalue) ⇒ Object
sets value of cell in column coli
69 |
# File 'lib/rspreadsheet/row.rb', line 69 def []=(coli,avalue); cells(coli).value=avalue end |
#add_row_above ⇒ Object Also known as: insert_row_above
Inserts row above itself (and shifts itself and all following rows down)
109 110 111 |
# File 'lib/rspreadsheet/row.rb', line 109 def add_row_above parent.add_row_above(rowi) end |
#cells(*params) ⇒ Object Also known as: cell
49 50 51 52 53 54 55 |
# File 'lib/rspreadsheet/row.rb', line 49 def cells(*params) if params.length == 1 subitems(Tools.convert_column_name_to_index(params[0])) else subitems(*params) end end |
#cellvalues ⇒ Array
return array of cell values
@worksheet[3,3] = "text"
@worksheet[3,1] = 123
@worksheet.rows(3).cellvalues # => [123, nil, "text"]
86 87 88 |
# File 'lib/rspreadsheet/row.rb', line 86 def cellvalues cells.collect{|c| c.value} end |
#cellvalues=(avalue) ⇒ Object
sets values of cells of row to values from avalue
. Attention: it deletes the rest of row
@row = @worksheet.rows(5)
@row.values = ["January", "Feb", nil, 4] # => | January | Feb | | 4 |
@row[2] = "foo") # => | January | foo | | 4 |
76 77 78 79 |
# File 'lib/rspreadsheet/row.rb', line 76 def cellvalues=(avalue) self.truncate avalue.each_with_index{ |val,i| self[i+1] = val } end |
#clone_above_row(target_rowi) ⇒ Object
121 122 123 |
# File 'lib/rspreadsheet/row.rb', line 121 def clone_above_row(target_rowi) parent.clone_item_before(rowi, target_rowi) end |
#next_row ⇒ Object Also known as: next
114 |
# File 'lib/rspreadsheet/row.rb', line 114 def next_row; relative(+1) end |
#nonemptycells ⇒ Object
96 97 98 |
# File 'lib/rspreadsheet/row.rb', line 96 def nonemptycells nonemptycellsindexes.collect{ |index| subitem(index) } end |
#nonemptycellsindexes ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/rspreadsheet/row.rb', line 99 def nonemptycellsindexes myxmlnode = xmlnode if myxmlnode.nil? [] else worksheet.find_nonempty_subnode_indexes(myxmlnode, ) end end |
#prepare_subitem(coli) ⇒ Object
34 |
# File 'lib/rspreadsheet/row.rb', line 34 def prepare_subitem(coli); Cell.new(worksheet,rowi,coli) end |
#relative(rowi_offset) ⇒ Object
117 118 119 |
# File 'lib/rspreadsheet/row.rb', line 117 def relative(rowi_offset) worksheet.row(self.rowi+rowi_offset) end |
#style_name=(value) ⇒ Object
92 93 94 95 |
# File 'lib/rspreadsheet/row.rb', line 92 def style_name=(value); detach_if_needed Tools.set_ns_attribute(xmlnode,'table','style-name',value) end |
#subnode_options ⇒ Object
29 30 31 32 33 |
# File 'lib/rspreadsheet/row.rb', line 29 def ; { :node_name => 'table-cell', :alt_node_names => ['covered-table-cell'], :repeated_attribute => 'number-columns-repeated' } end |