There are not many ways to generate Excel files readable on all Office versions, especially using Ruby:
- the “spreadsheet” gem;
- the OLE automation tools Microsoft provides (“Win32OLE” library);
- an appropriate library in another language (such as Apache POI – which can also produce PowerPoint files – or JExcel API, both written in Java).
The “spreadsheet” gem
This gem is only compatible with Ruby 1.8 (1.9 support is planned for the 1.0 version of the module) and hasn’t been updated since February 2010 on the author’s personal git and September 2009 for the public version.
This prevents the upgrade to Ruby 1.9. Moreover, this gem does not support (yet) formulas and images.
If these two issues do not bother you, spreadsheet may be the right tool for you. It seems to work fine but I don’t know if it handles cell formatting.
Microsoft’s “Win32OLE” library for OLE automation
WARNING: OLE automation is not suitable to generate files on the server side, because it requires Office to be installed on the machine, together with the Windows OS, and is not designed to handle a heavy charge and lots of operations.
Further information on this technique is available on Microsoft’s support website and Aspose’s website.
Linking a Java lib to Ruby with Ruby Java Bridge a.k.a. RJB (JRuby not required)
There are many free and open-source Java tools for Excel file generation (Apache POI, JExcel API, jXLS) and also commercial software such as Aspose.Cells that can be used with RJB in a Ruby application. RJB allows you to load the Java Virtual Machine within Ruby and manipulate Java objects just as if you were in a Java application.
On a performance level, according to my tests, it takes 4.68s for Aspose.Cells, 4.40s for POI and 2.85s for JExcel API to generate a 256×1000 cells document. As for functionalities and API each product offers they are very similar.
If you only have to deal with Excel files JExcel API is a powerful tool with good performances. Apache POI is also interresting because it supports other Office documents (PowerPoint and Word with Outlook, Visio and Publisher extensions on the way) and the new Office format (Office Open XML) for recent Office versions.
In my next blog entry, I will try to explain how to use Apache POI with Ruby, with RJB acting as a bridge between Ruby and Java.
English
Français 