Sha256: 62675afaa8571ca6afd5c3ba8c74c74986596f143488351b443adc22b6e30127

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# Copyright:: (c) Autotelik Media Ltd 2011
# Author ::   Tom Statter
# Date ::     Aug 2011
# License::   MIT
#
# Details::   Export a model to Excel
#
#
if(Guards::jruby?)

  require 'jexcel_file'
  require 'generator_base'

  module ARLoader


    class ExcelGenerator < GeneratorBase

      attr_accessor :excel, :filename
  

      def initialize(filename)
        @excel = nil
        @filename = filename
      end

  
      # Create an Excel file representing supplied Model
    
      def generate(model, options = {})

        @filename = options[:filename] if  options[:filename]

        @excel = JExcelFile.new()

        sheet = @excel.create_sheet( model.name )

        @excel.create_row(0)

        MethodMapper.find_operators( model )

        # header row
        unless(MethodMapper.assignments[model].empty?)
          row = sheet.createRow(0)
          cell_index = 0
          MethodMapper.assignments[model].each do |operator|
            row.createCell(cell_index).setCellValue(operator)
            cell_index += 1
          end
        end
    
        @excel.save( filename )
      end

  
      # Create an Excel file representing supplied Model

      def export(items, options = {})

        @filename = options[:filename] if  options[:filename]

        @excel = JExcelFile.new()

        @excel.to_xls(items)

        @excel.save( filename )
      end

    end
 
  end
else
  raise "BAD RUBY : PLEASE USE JRuby - Sorry JExcelFile requires JAVA via JRuby"
end # jruby

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_loader-0.0.9 lib/generators/excel_generator.rb