Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_color returns white #392

Open
jean-marc-voillequin opened this issue Mar 18, 2021 · 3 comments
Open

fill_color returns white #392

jean-marc-voillequin opened this issue Mar 18, 2021 · 3 comments

Comments

@jean-marc-voillequin
Copy link

Hello,

With the attached xlsx, rubyXL tells me that cell A1 is white filled, whereas it is grey filled.

require 'rubyXL'
require 'rubyXL/convenience_methods'
wb = RubyXL::Parser.parse('a.xlsx')
puts(wb[0][0][0].fill_color)

--> ffffff

Did i missed something?
Thanks and regards
a.xlsx

@darkBuddha
Copy link

darkBuddha commented Jan 7, 2022

It's the same for me, on another sheet. It is #d9d9d9. I guess, grayscales are saved white, and their "brightness" gets reduced, in a separate value.

@kikuhama
Copy link

I found same probrem.
It seems that the fill color specified by index (not RGB) is ignored and fill_color method returns 'ffffff'.

@Lukom
Copy link

Lukom commented Oct 25, 2023

I found out the same – indexed colors are ignored.. I've composed such helper method to check color AND indexed color:

class RubyXlUtils
  class << self

    def cell_color(cell)
      return unless cell
      color = cell.workbook.get_fill_color(cell.get_cell_xf)&.then { _1.last(6).downcase }
      if color == 'ffffff'
        color = cell_indexed_color(cell) || 'ffffff'
      end
      color
    end

    def cell_indexed_color(cell)
      if (fill_id = cell.get_cell_xf.fill_id)
        if (color_index = cell.workbook.fills[fill_id].pattern_fill&.fg_color&.indexed)
          if (indexed_color = cell.workbook.stylesheet.colors&.indexed_colors&.dig(color_index))
            indexed_color.rgb.last(6).downcase
          end
        end
      end
    end

  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants