# Ruby and Excel and colour question

**URL:** <https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723>\
**Category:** Ruby\
**Created:** [October 5, 2009, 2:08pm UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723 "2009-10-05T14:08:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [October 5, 2009, 2:08pm UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723/1 "2009-10-05T14:08:17Z")

</div>

Dear all,

I need to be able to write a file in Excel format, where the  
fields have different background colours based on  
some condition which is evaluated based on the entries  
at runtime.  
I tried to look at the spreadsheet gem, but couldn’t figure out how to  
do it. I’d much prefer if you could point me to a solution that  
is platform-independent (Excel files can be opened  
from OpenOffice etc.) and/or would work together with JRuby.

Thank you very much !

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [October 5, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723/2 "2009-10-05T22:13:05Z")

</div>

On Mon, Oct 5, 2009 at 7:07 AM, Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dear all,
> 
> I need to be able to write a file in Excel format, where the  
> fields have different background colours based on  
> some condition which is evaluated based on the entries  
> at runtime.  
> I tried to look at the spreadsheet gem, but couldn’t figure out how to do it. I’d much prefer if you could point me to a solution that  
> is platform-independent (Excel files can be opened  
> from OpenOffice etc.) and/or would work together with JRuby.

OpenOffice has some Java API support for accessing and manipulating  
files. I have not tried it, but I know there are examples of doing it  
from Java. JRuby should be able to access those Java classes just  
fine.

-Tom

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [October 7, 2009, 2:30am UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723/3 "2009-10-07T02:30:55Z")

</div>

On Oct 5, 8:07 am, Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dear all,
> 
> I need to be able to write a file in Excel format, where the  
> fields have different background colours based on  
> some condition which is evaluated based on the entries  
> at runtime.  
> I tried to look at the spreadsheet gem, but couldn’t figure out how to do it. I’d much prefer if you could point me to a solution that  
> is platform-independent (Excel files can be opened  
> from OpenOffice etc.) and/or would work together with JRuby.

The most popular platform-independent Excel creation library is POI  
([http://poi.apache.org](http://poi.apache.org)). It’s a java library so you should be able to  
use it from JRuby. You should be able to put in the formulas that  
change the background color based on runtime content.

- Mark.

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [October 9, 2009, 2:37am UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723/4 "2009-10-09T02:37:09Z")

</div>

Gilbo wrote:

> > 
> 
> have a look at surpass - it might be enough for what you want  
> (not sure about JRuby support though)
> 
> [http://surpass.rubyforge.org/](http://surpass.rubyforge.org/)
> 
> HTH
> 
> Mike

Wow! Surpass looks amazing! I was thinking of using jruby to invoke the  
java package OpenXLS to satisfy a similar requirement, but if this works  
it will be much easier.

Steve

---

<div class="post-metadata">

**Author:** ![Axel\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7c8e57/32.png) [@Axel\_E](https://www.ruby-forum.com/u/Axel_E)\
**Post date:** [October 9, 2009, 1:15am UTC](https://www.ruby-forum.com/t/ruby-and-excel-and-colour-question/176723/5 "2009-10-09T01:15:47Z")

</div>

On Oct 5, 1:07 pm, Axel E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thank you very much !
> 
> Best regards,
> 
> ## Axel
> 
> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -  
> sicherer, schneller und einfacher! [Aktuelle Nachrichten aus Politik, Wirtschaft & Panorama | GMX](http://portal.gmx.net/de/go/atbrowser)

Axel,

have a look at surpass - it might be enough for what you want  
(not sure about JRuby support though)

[http://surpass.rubyforge.org/](http://surpass.rubyforge.org/)

HTH

Mike
