Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/to_xls.rb

Instance Method Summary collapse

Instance Method Details

#to_xls(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/to_xls.rb', line 6

def to_xls(options = {})
  book = Spreadsheet::Workbook.new

  each do |key, value|
    sheet = book.create_worksheet
    sheet.name = key.to_s.gsub('_', ' ').titleize
    value.to_xls({ :sheet => sheet }.merge(options[key] || {}))
  end
  
  return book
end

#to_xls_data(options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/to_xls.rb', line 18

def to_xls_data(options = {})
  data = StringIO.new('')
  self.to_xls(options).write(data)
  return data.string
end