Class: POI::Worksheets

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

Instance Method Summary collapse

Constructor Details

#initialize(workbook) ⇒ Worksheets

Returns a new instance of Worksheets.



5
6
7
8
# File 'lib/poi/workbook/worksheet.rb', line 5

def initialize(workbook)
  @workbook = workbook
  @poi_workbook = workbook.poi_workbook
end

Instance Method Details

#[](index_or_name) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/poi/workbook/worksheet.rb', line 10

def [](index_or_name)
  worksheet = case
    when index_or_name.kind_of?(Numeric)
      @poi_workbook.get_sheet_at(index_or_name) || @poi_workbook.create_sheet
    else 
      @poi_workbook.get_sheet(index_or_name) || @poi_workbook.create_sheet(index_or_name)
  end
  Worksheet.new(worksheet, @workbook)
end

#eachObject



24
25
26
# File 'lib/poi/workbook/worksheet.rb', line 24

def each
  (0...size).each { |i| yield Worksheet.new(@poi_workbook.get_sheet_at(i), @workbook) }
end

#sizeObject



20
21
22
# File 'lib/poi/workbook/worksheet.rb', line 20

def size
  @poi_workbook.number_of_sheets
end