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

new(aworksheet,arowi) click to toggle source
# 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

[](coli) click to toggle source
@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
[]=(coli,avalue) click to toggle source

@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
_shift_by(diff) click to toggle source

@!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

Calls superclass method
# File lib/rspreadsheet/row.rb, line 129
def _shift_by(diff)
  super
  @itemcache.each_value{ |cell| cell.set_rowi(rowi) }
end
add_row_above() click to toggle source

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
Also aliased as: insert_row_above
cell(*params)
Alias for: cells
cells(*params) click to toggle source

@!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
Also aliased as: cell
cellvalues() click to toggle source
@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
cellvalues=(avalue) click to toggle source

@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
clone_above_row(target_rowi) click to toggle source
# File lib/rspreadsheet/row.rb, line 121
def clone_above_row(target_rowi)
  parent.clone_item_before(rowi, target_rowi)
end
insert_row_above()
Alias for: add_row_above
next()
Alias for: next_row
next_row() click to toggle source
# File lib/rspreadsheet/row.rb, line 114
def next_row; relative(+1) end
Also aliased as: next
nonemptycells() click to toggle source
# File lib/rspreadsheet/row.rb, line 96
def nonemptycells
  nonemptycellsindexes.collect{ |index| subitem(index) }
end
nonemptycellsindexes() click to toggle source
# 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
prepare_subitem(coli) click to toggle source
# File lib/rspreadsheet/row.rb, line 34
def prepare_subitem(coli); Cell.new(worksheet,rowi,coli) end
relative(rowi_offset) click to toggle source
# File lib/rspreadsheet/row.rb, line 117
def relative(rowi_offset)
  worksheet.row(self.rowi+rowi_offset)
end
rowi() click to toggle source
@return [Integer] row index of the row

@!attribute [r] rowi

# File lib/rspreadsheet/row.rb, line 41
def rowi; index end
style_name=(value) click to toggle source

@!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
subnode_options() click to toggle source

@!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
worksheet() click to toggle source
@return [Worksheet] worksheet which contains the row

@!attribute [r] worksheet

# File lib/rspreadsheet/row.rb, line 38
def worksheet; parent end