Class: POI::Worksheet

Inherits:
Facade
  • Object
show all
Defined in:
lib/poi/workbook/worksheet.rb

Instance Method Summary collapse

Constructor Details

#initialize(worksheet, workbook) ⇒ Worksheet

Returns a new instance of Worksheet.



31
32
33
34
# File 'lib/poi/workbook/worksheet.rb', line 31

def initialize(worksheet, workbook)
  @worksheet = worksheet
  @workbook  = workbook
end

Instance Method Details

#[](row_index) ⇒ Object

Accepts a Fixnum or a String as the row_index

row_index as Fixnum: returns the 0-based row

row_index as String: assumes a cell reference within this sheet

if the value of the reference is non-nil the value is returned,
otherwise the referenced cell is returned


59
60
61
62
63
64
65
66
67
# File 'lib/poi/workbook/worksheet.rb', line 59

def [](row_index)
  if Fixnum === row_index
    rows[row_index]
  else
    ref = org.apache.poi.ss.util.CellReference.new(row_index)
    cell = rows[ref.row][ref.col]
    cell && cell.value ? cell.value : cell
  end
end

#first_rowObject



40
41
42
# File 'lib/poi/workbook/worksheet.rb', line 40

def first_row
  @worksheet.first_row_num
end

#last_rowObject



44
45
46
# File 'lib/poi/workbook/worksheet.rb', line 44

def last_row
  @worksheet.last_row_num
end

#nameObject



36
37
38
# File 'lib/poi/workbook/worksheet.rb', line 36

def name
  @worksheet.sheet_name
end

#poi_worksheetObject



69
70
71
# File 'lib/poi/workbook/worksheet.rb', line 69

def poi_worksheet
  @worksheet
end

#rowsObject



48
49
50
# File 'lib/poi/workbook/worksheet.rb', line 48

def rows
  @rows ||= Rows.new(self)
end

#workbookObject



73
74
75
# File 'lib/poi/workbook/worksheet.rb', line 73

def workbook
  @workbook
end