Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
writeexcel Template handler (fileextension is .writeexcel) for Rails 3.0
require 'action_dispatch/http/mime_type'
require 'action_view'
require 'writeexcel'
class WriteExcelTemplateHandler < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable
def compile(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)
@arunmohan

This comment has been minimized.

Copy link

@arunmohan arunmohan commented Nov 20, 2011

It is not exporting xls, it shows some encrypted text in xls

@ream88

This comment has been minimized.

Copy link
Owner Author

@ream88 ream88 commented Nov 20, 2011

@arunmohan which Rails version are you using? This works with Rails 3.0 only.

@arunmohan

This comment has been minimized.

Copy link

@arunmohan arunmohan commented Nov 20, 2011

@ream88

This comment has been minimized.

Copy link
Owner Author

@ream88 ream88 commented Nov 20, 2011

Ok, I will try to make a Rails 2.3.5 handler too.

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