Class: Rspreadsheet::Row

Inherits:
XMLTiedItem
  • Object
show all
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.rows(5)

Mostly you will this object to access row cells

@row.cells(2)     # identical to @worksheet.rows(5).cells(2)
@row[2]           # identical to @worksheet[5,2] or @row.cells(2)

or 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

Syntactic sugar collapse

Other methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(aworksheet, arowi) ⇒ Row



33
34
35
36
37
# File 'lib/rspreadsheet/row.rb', line 33

def initialize(aworksheet,arowi)
  @worksheet = aworksheet
  @rowi = arowi
  @itemcache = Hash.new  #TODO: move to module XMLTiedArray
end

Instance Attribute Details

#rowiInteger (readonly)



31
32
33
# File 'lib/rspreadsheet/row.rb', line 31

def rowi
  @rowi
end

#worksheetWorksheet (readonly)



28
29
30
# File 'lib/rspreadsheet/row.rb', line 28

def worksheet
  @worksheet
end

Instance Method Details

#[](coli) ⇒ String or Float or Date

returns value of the cell at column coli



47
# File 'lib/rspreadsheet/row.rb', line 47

def [](coli); cells(coli).value end

#[]=(coli, avalue) ⇒ Object

sets value of the cell at column coli



51
# File 'lib/rspreadsheet/row.rb', line 51

def []=(coli,avalue); cells(coli).value=avalue end

#add_row_aboveObject

Inserts row above itself (and shifts itself and all following rows down)



72
73
74
# File 'lib/rspreadsheet/row.rb', line 72

def add_row_above
  parent.add_row_above(rowi)
end

#cells(*params) ⇒ Object



42
# File 'lib/rspreadsheet/row.rb', line 42

def cells(*params); subitems(*params) end

#cellvaluesObject



75
76
77
# File 'lib/rspreadsheet/row.rb', line 75

def cellvalues
  cells.collect{|c| c.value}
end

#nonemptycellsObject



59
60
61
# File 'lib/rspreadsheet/row.rb', line 59

def nonemptycells
  nonemptycellsindexes.collect{ |index| subitem(index) }
end

#nonemptycellsindexesObject



62
63
64
65
66
67
68
69
# File 'lib/rspreadsheet/row.rb', line 62

def nonemptycellsindexes
  myxmlnode = xmlnode
  if myxmlnode.nil?
    []
  else
    @worksheet.find_nonempty_subnode_indexes(myxmlnode, {:xml_items_node_name => 'table-cell', :xml_repeated_attribute => 'number-columns-repeated'})
  end
end

#style_name=(value) ⇒ Object



55
56
57
58
# File 'lib/rspreadsheet/row.rb', line 55

def style_name=(value); 
  detach_if_needed
  Tools.set_ns_attribute(xmlnode,'table','style-name',value)
end

#xmlnodeObject



39
# File 'lib/rspreadsheet/row.rb', line 39

def xmlnode; parent.find_my_subnode_respect_repeated(index, xml_options)  end