randym/axlsx — Issue #13: behaviors acting on Axlsx::Color
Author: dkmdnielsen
Created: 2012-01-11 16:37:39+00:00
State: open

Slick Library! Thank you.

The implementation of Color is confusing to me. For example, it feels intuitive for one to code up his/her style colors upfront in a class, such as the following constant, and then use that constant in multiple places.

class AAN_Excel
COLOR_HEADER_BACKGROUND = Axlsx::Color.new(:rgb=>"FF99CCFF")

Once constructed, the style building would act on the class instance and react according. For example:

def construct_styles(wb)
wb.styles {|s|
@hdr_style = s.add_style( :bg_color => COLOR_HEADER_BACKGROUND )
}

I implemented the above in ./lib/axlsx/stylesheet/styles.rb as:

fill = if options[:bg_color]
color = options[:bg_color].class == Axlsx::Color ? options[:bg_color] : Color.new(:rgb=>options[:bg_color])
pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
fills << Fill.new(pattern)
else
0
end

It would be nice if Axlsx::Font could be acted on the same way. This would give the programmer the ability do define all the color and font instances as constants, and then use those constants when multiple sheets are being structured.

Or am I off base...missing something I shouldn't?

Thanks for your time and consideration. I would code up suggested changes and submit them, but I do not know how. I've never done that before.

dvn