RailsXLS Revived October 2nd, 2008
RailsXLS is a plugin to generate Excel files from a .rxls view. It uses a Java Bridge to talk to the Jakarta POI library. I’ve used this plugin in a few projects and it works great for generating .xls files.
On a recent project I once again needed an “Export to Excel” feature. The project is on Rails Edge, and apparently there were some changes to how TemplateHandlers are handled since the plugin was written. I dove into the code and recreated the plugin for Rails Edge / 2.2.
You can find the new plugin on github
It’s usage is quite easy:
# in your environment.rb Mime::Type.register "application/excel", :xls # in controller def index @clients = Client.all respond_to do |speaks| speaks.html speaks.xls { render :layout => false } end end # in index.xls.rxls sheet = workbook.createSheet("Client List") @clients.each_with_index do |client, index| row = sheet.createRow(index) row.createCell(0).setCellValue(client.id) row.createCell(1).setCellValue(client.name) end
As you can see there are still some rough patches in the view. I’m working on a wrapper around this, so all obvious tasks can be easily performed.
Any comments/suggestions for the plugin are very welcome! A big thanks to Venkata Subramaniyan for writing the initial plugin, which can be found here
l 12 comments »