# How can I use Ruby with MS Excel?

**URL:** <https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835>\
**Category:** Ruby\
**Created:** [June 8, 2010, 4:10pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835 "2010-06-08T16:10:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 8, 2010, 4:10pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/1 "2010-06-08T16:10:43Z")

</div>

As much as I hate to say it, Microsoft Excel is here to stay and will  
continue to be the most popular tool among engineers and scientists.  
When I say engineers, I mean mechanical, civil, environmental, chemical  
engineers. The new version of Excel has some very nice graphical  
capability.

I love Ruby and hate Visual Basic with passion. Hopefully that goes  
without further explanation.

Could someone here help me envision a way to make use of Excel for the  
input/output and Ruby for the model logic?

In the perfect world, I would set up spreadsheet columns in Excel with  
input data. Maybe I would have a couple of GUI windows for other inputs.  
Then I could run the logic written in Ruby and output would be fed back  
to spreadsheet columns in Excel. Then I could make use of their nice  
graphing capabilities.

Has anyone looked into this question?

Thank you.

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 8, 2010, 4:25pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/2 "2010-06-08T16:25:22Z")

</div>

Jason L. wrote:

> As much as I hate to say it, Microsoft Excel is here to stay and will  
> continue to be the most popular tool among engineers and scientists.  
> When I say engineers, I mean mechanical, civil, environmental, chemical  
> engineers. The new version of Excel has some very nice graphical  
> capability.
> 
> I love Ruby and hate Visual Basic with passion. Hopefully that goes  
> without further explanation.
> 
> Could someone here help me envision a way to make use of Excel for the  
> input/output and Ruby for the model logic?
> 
> In the perfect world, I would set up spreadsheet columns in Excel with  
> input data. Maybe I would have a couple of GUI windows for other inputs.  
> Then I could run the logic written in Ruby and output would be fed back  
> to spreadsheet columns in Excel. Then I could make use of their nice  
> graphing capabilities.
> 
> Has anyone looked into this question?
> 
> Thank you.

Since it looks like on every computer excel is set up, you can connect  
to an excel OLE server and issue all the commands you can from  
VisualBasic (as far as I know). Have a look at  
[Ruby on Windows: excel](http://rubyonwindows.blogspot.com/search/label/excel) which has several  
blog posts about using Ruby together with excel. This post may makes a  
good starting point:  
[Ruby on Windows: RubyGarden Archives: Scripting Excel](http://rubyonwindows.blogspot.com/2008/01/rubygarden-archives-scripting-excel.html)

Marvin

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 9, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/3 "2010-06-09T14:46:33Z")

</div>

(2010/06/09 20:39), Josh C. wrote:

> Any resources about how to access those formats on a Unix/Linux machine?

I found spreadsheet gem for read/write Excel files.  
According to project page, this library works on any platform.

[http://spreadsheet.rubyforge.org/](http://spreadsheet.rubyforge.org/)  
[http://rubyforge.org/projects/spreadsheet/](http://rubyforge.org/projects/spreadsheet/)

sorry, I have not use it yet. FYI.

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 9, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/4 "2010-06-09T13:40:23Z")

</div>

On Tue, Jun 8, 2010 at 9:25 AM, Marvin GÃ¼lker [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Could someone here help me envision a way to make use of Excel for the  
> > Thank you.  
> > Marvin  
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Any resources about how to access those formats on a Unix/Linux machine?

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 9, 2010, 5:05pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/5 "2010-06-09T17:05:19Z")

</div>

There is one caveat which may no longer be a problem. It’s been a while  
since I’ve tried to do this. It used to be that there was no way with  
the ruby com libraries to access any com interface that an object  
exposed other than the default one. Some of the objects expose multiple  
interfaces that provide different sets of functionality, just as you  
would expect an interface to do. If you can’t get a pointer to that  
interface, you just can’t do those things on that object.

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 9, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/6 "2010-06-09T14:51:57Z")

</div>

ç”°ä¸­ è¡ wrote:

> (2010/06/09 20:39), Josh C. wrote:
> 
> > Any resources about how to access those formats on a Unix/Linux machine?
> 
> I found spreadsheet gem for read/write Excel files.  
> According to project page, this library works on any platform.
> 
> [http://spreadsheet.rubyforge.org/](http://spreadsheet.rubyforge.org/)  
> [http://rubyforge.org/projects/spreadsheet/](http://rubyforge.org/projects/spreadsheet/)
> 
> sorry, I have not use it yet. FYI.  
> Just found this:  
> [http://roo.rubyforge.org/](http://roo.rubyforge.org/)

This gem allows you to access the content of

```
* Open-office spreadsheets (.ods)
* Excel spreadsheets (.xls)
* Google (online) spreadsheets
* Excelâ€™s new file format .xlsx

```

---

<div class="post-metadata">

**Author:** ![leveille](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@leveille](https://www.ruby-forum.com/u/leveille)\
**Post date:** [June 10, 2010, 2:10am UTC](https://www.ruby-forum.com/t/how-can-i-use-ruby-with-ms-excel/189835/7 "2010-06-10T02:10:19Z")

</div>

> Any resources about how to access those formats on a Unix/Linux machine?

I have had success with JRuby and the Apache POI library (http://  
[poi.apache.org](http://poi.apache.org)), which is fairly feature-ful.
