Method: RubyExcel::Workbook#sheets

Defined in:
lib/rubyexcel.rb

#sheets(ref = nil) {|RubyExcel::Sheet| ... } ⇒ RubyExcel::Sheet, Enumerator

Select a Sheet or iterate through them

Parameters:

  • ref (Fixnum, String, Regexp, nil) (defaults to: nil)

    the reference to select a Sheet by

Yields:

  • (RubyExcel::Sheet)

    yields each sheet, if there is no argument and a block is given

Returns:

  • (RubyExcel::Sheet)

    if a search term was given

  • (Enumerator)

    if nil or no argument given



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/rubyexcel.rb', line 210

def sheets( ref=nil )
  if ref.nil?
    return to_enum (:each) unless block_given?
    each { |s| yield s }
  else
    case ref
    when Fixnum ; @sheets[ ref - 1 ]
    when String ; @sheets.find { |s| s.name =~ /^#{ ref }$/i }
    when Regexp ; @sheets.find { |s| s.name =~ ref }
    end
  end
end