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.
Instance Attribute Summary collapse
-
#rowi ⇒ Integer
readonly
Row index of the row.
-
#worksheet ⇒ Worksheet
readonly
Worksheet which contains the row.
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
Inserts row above itself (and shifts itself and all following rows down).
- #next_row ⇒ Object (also: #next)
- #nonemptycells ⇒ Object
- #nonemptycellsindexes ⇒ Object
- #relative(rowi_offset) ⇒ Object
- #style_name=(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(aworksheet, arowi) ⇒ Row
constructor
A new instance of Row.
Constructor Details
#initialize(aworksheet, arowi) ⇒ Row
35 36 37 38 |
# File 'lib/rspreadsheet/row.rb', line 35 def initialize(aworksheet,arowi) initialize_xml_tied_array initialize_xml_tied_item(aworksheet,arowi) end |
Instance Attribute Details
#rowi ⇒ Integer (readonly)
33 |
# File 'lib/rspreadsheet/row.rb', line 33 def rowi; index end |
#worksheet ⇒ Worksheet (readonly)
30 |
# File 'lib/rspreadsheet/row.rb', line 30 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
58 |
# File 'lib/rspreadsheet/row.rb', line 58 def [](coli); cells(coli).value end |
#[]=(coli, avalue) ⇒ Object
sets value of cell in column coli
61 |
# File 'lib/rspreadsheet/row.rb', line 61 def []=(coli,avalue); cells(coli).value=avalue end |
#add_row_above ⇒ Object
Inserts row above itself (and shifts itself and all following rows down)
101 102 103 |
# File 'lib/rspreadsheet/row.rb', line 101 def add_row_above parent.add_row_above(rowi) end |
#cells(*params) ⇒ Object Also known as: cell
41 42 43 44 45 46 47 |
# File 'lib/rspreadsheet/row.rb', line 41 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"]
78 79 80 |
# File 'lib/rspreadsheet/row.rb', line 78 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 |
68 69 70 71 |
# File 'lib/rspreadsheet/row.rb', line 68 def cellvalues=(avalue) self.truncate avalue.each_with_index{ |val,i| self[i+1] = val } end |
#next_row ⇒ Object Also known as: next
105 |
# File 'lib/rspreadsheet/row.rb', line 105 def next_row; relative(+1) end |
#nonemptycells ⇒ Object
88 89 90 |
# File 'lib/rspreadsheet/row.rb', line 88 def nonemptycells nonemptycellsindexes.collect{ |index| subitem(index) } end |
#nonemptycellsindexes ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/rspreadsheet/row.rb', line 91 def nonemptycellsindexes myxmlnode = xmlnode if myxmlnode.nil? [] else worksheet.find_nonempty_subnode_indexes(myxmlnode, ) end end |
#relative(rowi_offset) ⇒ Object
108 109 110 |
# File 'lib/rspreadsheet/row.rb', line 108 def relative(rowi_offset) worksheet.row(self.rowi+rowi_offset) end |
#style_name=(value) ⇒ Object
84 85 86 87 |
# File 'lib/rspreadsheet/row.rb', line 84 def style_name=(value); detach_if_needed Tools.set_ns_attribute(xmlnode,'table','style-name',value) end |