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, sheet.
- #to_xls_data(options = {}) ⇒ Object
Instance Method Details
#to_xls(options = {}) ⇒ Object
Options for to_xls: columns, name, header, sheet
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/to_xls.rb', line 27 def to_xls( = {}) sheet = [:sheet] unless sheet book = Spreadsheet::Workbook.new sheet = book.create_worksheet sheet.name = [:name] || 'Sheet 1' end 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 || sheet end |
#to_xls_data(options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/to_xls.rb', line 61 def to_xls_data( = {}) data = StringIO.new('') self.to_xls().write(data) return data.string end |