class Rspreadsheet::Row
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 {Rspreadsheet::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.
Public Class Methods
# File lib/rspreadsheet/row.rb, line 43 def initialize(aworksheet,arowi) initialize_xml_tied_array initialize_xml_tied_item(aworksheet,arowi) end
Public Instance Methods
@return [String or Float or Date] value of the cell
@param coli [Integer ot String] colum index of the cell of colum letter 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
# File lib/rspreadsheet/row.rb, line 66 def [](coli); cells(coli).value end
@param avalue [Array] sets value of cell in column `coli`
# File lib/rspreadsheet/row.rb, line 69 def []=(coli,avalue); cells(coli).value=avalue end
@!group Private methods, which should not be called directly @private shifts internal represetation of row by diff. This should not be called directly by user, it is only used by XMLTiedArray_WithRepeatableItems
as hook when shifting around rows
# File lib/rspreadsheet/row.rb, line 129 def _shift_by(diff) super @itemcache.each_value{ |cell| cell.set_rowi(rowi) } end
Inserts row above itself (and shifts itself and all following rows down)
# File lib/rspreadsheet/row.rb, line 109 def add_row_above parent.add_row_above(rowi) end
@!group Syntactic sugar
# 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
@return [Array
return array of cell values
@worksheet[3,3] = "text" @worksheet[3,1] = 123 @worksheet.rows(3).cellvalues # => [123, nil, "text"]
# File lib/rspreadsheet/row.rb, line 86 def cellvalues cells.collect{|c| c.value} end
@param avalue [Array] array with values 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 |
# File lib/rspreadsheet/row.rb, line 76 def cellvalues=(avalue) self.truncate avalue.each_with_index{ |val,i| self[i+1] = val } end
# File lib/rspreadsheet/row.rb, line 121 def clone_above_row(target_rowi) parent.clone_item_before(rowi, target_rowi) end
# File lib/rspreadsheet/row.rb, line 114 def next_row; relative(+1) end
# File lib/rspreadsheet/row.rb, line 96 def nonemptycells nonemptycellsindexes.collect{ |index| subitem(index) } end
# File lib/rspreadsheet/row.rb, line 99 def nonemptycellsindexes myxmlnode = xmlnode if myxmlnode.nil? [] else worksheet.find_nonempty_subnode_indexes(myxmlnode, subnode_options) end end
# File lib/rspreadsheet/row.rb, line 34 def prepare_subitem(coli); Cell.new(worksheet,rowi,coli) end
# File lib/rspreadsheet/row.rb, line 117 def relative(rowi_offset) worksheet.row(self.rowi+rowi_offset) end
@return [Integer] row index of the row
@!attribute [r] rowi
# File lib/rspreadsheet/row.rb, line 41 def rowi; index end
@!group Other methods
# File lib/rspreadsheet/row.rb, line 92 def style_name=(value); detach_if_needed Tools.set_ns_attribute(xmlnode,'table','style-name',value) end
@!group XMLTiedArray_WithRepeatableItems
related methods
# File lib/rspreadsheet/row.rb, line 29 def subnode_options; { :node_name => 'table-cell', :alt_node_names => ['covered-table-cell'], :repeated_attribute => 'number-columns-repeated' } end
@return [Worksheet] worksheet which contains the row
@!attribute [r] worksheet
# File lib/rspreadsheet/row.rb, line 38 def worksheet; parent end