Skip to content

Instantly share code, notes, and snippets.

@erlingur
Forked from ream88/writeexcel_template_handler.rb
Last active December 10, 2015 06:08
Show Gist options
  • Save erlingur/4392052 to your computer and use it in GitHub Desktop.
Save erlingur/4392052 to your computer and use it in GitHub Desktop.
require 'action_dispatch/http/mime_type'
require 'action_view'
require 'active_support'
require 'writeexcel'
class WriteExcelTemplateHandler
def self.call(template)
%{
tmp = Tempfile.new('writeexcel')
workbook = WriteExcel.new(tmp.path)
#{template.source}
workbook.close
tmp.read
}
end
end
Mime::Type.register('application/vnd.ms-excel', :xls)
::ActionView::Template.register_template_handler('writeexcel', WriteExcelTemplateHandler)
@erlingur
Copy link
Author

Rails 3.1+ compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment