Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/to_xls.rb
Instance Method Summary collapse
-
#to_xls(options = {}) ⇒ Object
Options for to_xls: columns, name, header.
- #to_xls_data(options = {}) ⇒ Object
Instance Method Details
#to_xls(options = {}) ⇒ Object
Options for to_xls: columns, name, header
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/to_xls.rb', line 7 def to_xls( = {}) book = Spreadsheet::Workbook.new sheet = book.create_worksheet sheet.name = [:name] || 'Sheet 1' if self.any? columns = [:columns] || self.first.attributes.keys.sort if columns.any? line = 0 unless [:headers] == false if [:headers].is_a?(Array) sheet.row(0).concat [:headers].collect(&:to_s) else aux_headers_to_xls(self.first, columns, sheet.row(0)) end line = 1 end self.each do |item| row = sheet.row(line) columns.each {|column| aux_to_xls(item, column, row)} line += 1 end end end return book end |
#to_xls_data(options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/to_xls.rb', line 40 def to_xls_data( = {}) data = StringIO.new('') self.to_xls().write(data) return data.string end |