views:

212

answers:

1

I want to get the background color of a cell of an Excel worksheet. I have already tried the following:

begin; require 'rubygems'; rescue LoadError; end
require 'appscript'
f = MacTypes::Alias.path(File.join(File.dirname(__FILE__), "planning.xls"))
excel = Appscript.app("Microsoft Excel")
excel.activate
excel.open f

w1 = excel.worksheets[1]

1.upto(10) do |i|
  1.upto(10) do |j|
    cell = w1.rows[i].cells[j]
    print cell.value.get.to_s + " (#{cell.style_object.interior_object.pattern_color.get})"
  end
  puts ""
end

Unfortunately, I only get the cells value I can't seem to find the method that should give me the background color.

+2  A: 

This is gives the value of the background color:

cell.interior_object.color.get
Jeroen van Dijk