class Exportable::ExportMethods::XlsExporter::Exporter
Public Class Methods
new(model)
click to toggle source
# File lib/exportable/export_methods/xls_exporter.rb, line 17 def initialize(model) @book = Spreadsheet::Workbook.new @model = model end
Public Instance Methods
export(options)
click to toggle source
# File lib/exportable/export_methods/xls_exporter.rb, line 22 def export(options) sheet = @book.create_worksheet i = 0 if options[:header] sheet.row(i).concat(options[:fields].map(&:to_s)) i += 1 end @model.where(nil).find_each do |record| sheet.row(i).concat options[:fields].map { |attr| record.send(attr).to_s } i += 1 end write_io_output end
write_io_output()
click to toggle source
# File lib/exportable/export_methods/xls_exporter.rb, line 36 def write_io_output output = StringIO.new @book.write output output.string end