Created
July 19, 2011 23:34
-
-
Save ream88/1094013 to your computer and use it in GitHub Desktop.
writeexcel Template handler (fileextension is .writeexcel) for Rails 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 which Rails version are you using? This works with Rails 3.0 only.
Rails 2.3.5
…On Sun, Nov 20, 2011 at 7:37 PM, Mario Uher < ***@***.*** > wrote:
@arunmohan which Rails version are you using? This works with Rails 3.0
only.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1094013
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
It is not exporting xls, it shows some encrypted text in xls