From 1df3e7607ac6b593a270b4155c89e1f8c9bbdffc Mon Sep 17 00:00:00 2001 From: Daniel Lockhart Date: Tue, 16 Feb 2016 15:34:38 +0000 Subject: [PATCH] Update excel.rb to export as worksheet This ensures that errors like http://i.imgur.com/UTUtwcq.png do not occur when opening in later versions of Office --- .../exportable_formats/excel.rb | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/make_exportable/exportable_formats/excel.rb b/lib/make_exportable/exportable_formats/excel.rb index e677078..ae9df3d 100644 --- a/lib/make_exportable/exportable_formats/excel.rb +++ b/lib/make_exportable/exportable_formats/excel.rb @@ -7,6 +7,7 @@ class Excel < ExportableFormat #:nodoc: 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;' @@ -16,18 +17,31 @@ def initialize(data_set, data_headers=[]) def generate generate_header_option(data_headers) - output = "\n" + output = "\n" + output << "\n" + output << "\t\n" + output << "\t\t
\n" + unless data_headers.blank? - output << "\t\n" - output << data_headers.map {|h| "\t\t\n" }.join - output << "\t\n" + output << "\t\t\t\n" + output << data_headers.map {|h| "\t\t\t\t#{sanitize(h.humanize.titleize)}\n" }.join + output << "\t\t\t\n" end + data_set.each do |row| - output << "\t\n" - output << row.map {|field| "\t\t\n"}.join - output << "\t\n" + output << "\t\t\t\n" + output << row.map {|field| "\t\t\t\t#{sanitize(field)}\n" }.join + output << "\t\t\t\n" end - output << "
#{sanitize(h.humanize.titleize)}
#{sanitize(field)}
\n" + + output << "\t\t\n" + output << "\t\n" + output << "\n" + return output end