Skip to content

fill_color returns white #392

Open
Open

Description

@jean-marc-voillequin

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

Activity

  1. darkBuddha commented on Jan 7, 2022

    @darkBuddha

    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.

  2. kikuhama commented on Jul 31, 2023

    @kikuhama

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

  3. Lukom commented on Oct 25, 2023

    @Lukom

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions