module MakeExportable #:nodoc: class Excel < ExportableFormat #:nodoc: self.reference = :xls self.name = 'Excel' self.register_format attr_accessor :data_set, :data_headers def initialize(data_set, data_headers=[]) self.long = 'Microsoft Excel' self.mime_type = 'application/vnd.ms-excel; charset=utf-8;' self.data_set = data_set self.data_headers = data_headers end def generate generate_header_option(data_headers) output = "\n" unless data_headers.blank? output << "\t\n" output << data_headers.map {|h| "\t\t\n" }.join output << "\t\n" end data_set.each do |row| output << "\t\n" output << row.map {|field| "\t\t\n"}.join output << "\t\n" end output << "
#{sanitize(h.humanize.titleize)}
#{sanitize(field)}
\n" return output end def sanitize(value) value.gsub(//, '>') end end end