class Exporter::ExcelExporter

Public Instance Methods

process(data, options) click to toggle source
# File lib/exporter/exporters/excel_exporter.rb, line 6
def process(data, options)

  raise TypeError.new unless is_active_record?(data, options)

  columns = options[:columns] || data[0].class.attribute_names

  book = Spreadsheet::Workbook.new
  sheet = book.create_worksheet
  sheet.name = options[:sheet_name] || 'sheet1'
  sheet.row(0).concat columns
  data.each_with_index do |row, index|
    sheet.row(index+1).concat row.attributes.values_at(*columns)
  end

  ExcelDocument.new(book)
end