Sha256: 31ab144d390460ca8ea335ba6b8d0e226933bf2a96b2a2a914307ef7e5eb89e1

Contents?: true

Size: 485 Bytes

Versions: 5

Compression:

Stored size: 485 Bytes

Contents

module Excelizer
  class Writer
    require 'spreadsheet' unless defined?(Spreadsheet)

    def self.write(headers, records)
      book = Spreadsheet::Workbook.new
      sheet = book.create_worksheet
      
      sheet.row(0).push *headers
      records.each_with_index do |record, index|
        sheet.row(index + 1).push *record
      end
      
      self.persist book
    end

    def self.persist(book, file=StringIO.new)
      book.write file
      file.string
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
excelizer-0.2.0 lib/excelizer/writer.rb
excelizer-0.1.0 lib/excelizer/writer.rb
excelizer-0.0.9 lib/excelizer/writer.rb
excelizer-0.0.8 lib/excelizer/writer.rb
excelizer-0.0.7 lib/excelizer/writer.rb