Method: RubyExcel::Workbook#add

Defined in:
lib/rubyexcel.rb

#add(ref = false) ⇒ RubyExcel::Sheet Also known as: add_sheet

Adds a Sheet to the Workbook.

If no argument is given, names the Sheet 'Sheet' + total number of Sheets

Examples:

sheet = workbook.add
#=> RubyExcel::Sheet:0x2b3a0b8: Sheet1

Parameters:

  • ref (nil, RubyExcel::Sheet, String) (defaults to: false)

    the identifier or Sheet to add

Returns:



91
92
93
94
95
96
97
98
99
100
# File 'lib/rubyexcel.rb', line 91

def add( ref = false )
  case ref
  when false    ; s = Sheet.new( 'Sheet' + ( @sheets.count + 1 ).to_s, self )
  when Sheet  ; ( s = ref ).workbook = self
  when String ; s = Sheet.new( ref, self )
  else        ; fail TypeError, "Unsupported Type: #{ ref.class }"
  end
  @sheets << s
  s
end