3

I'm using the Roo ruby gem to parse an xlsx file.

Is there any way to get the background color of a cell? I've looked all around the code but couldn't find how to do it.

Opening a spreadsheet using roo is very straightforward:

spreadsheet = Roo::Excelx.new(file_path)
# Get me a sheet
sheet = spreadsheet.sheet("278")
# I happily thought excelx_format would return something that has
# to do with color, but it (sensibly) returns the cell format.
# In this case is GENERAL (no particular format)
puts sheet.excelx_format(6, 6)
3
  • Welcome to the community. Can you share a sample list of code of what you have already tried?
    – Phlume
    Apr 30, 2015 at 1:04
  • roo does not have implemented reader for background color Apr 30, 2015 at 1:16
  • Damn. You seem to know more about this than I do :) Any suggestions on how to proceed? Any "advanced" parsing feature that I could use with roo, like a method call to return raw cell information that I could parse?
    – diegoesp
    Apr 30, 2015 at 1:22

1 Answer 1

3

I looked around a little more and Roo does not seem to provide any advanced functions for custom inspection.

So I switched gems. I'm using spreadsheet now.

spreadsheet = Spreadsheet.open(file_path)
sheet = spreadsheet.worksheet("278")
row = sheet.row(5)
background_color = row.format(5).pattern_bg_color
1
  • Nice, but it can't open XLSX. RubyXL can read it, but no grayscales.
    – Howard
    Jan 7, 2022 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.