From 061d16b216f14e90f535ccd36e2eb902b4af3b9e Mon Sep 17 00:00:00 2001 From: Ankur Sethi Date: Sun, 26 May 2013 13:10:40 -0300 Subject: Update bg_color in conditional formatting Conditional formatting for background color fills is different for DXF. This must be undocumented and is quite annoying. I verified the behavior in Excel 2010 Mac and Windows. I didn't understand why background colors were not being applied even though the style was being applied for conditional formatting. Looking at styles.xml I saw that it is different in a file created by Excel. I have updated the code to reflect it and tested in Mac and Windows. --- lib/axlsx/stylesheet/styles.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 8cd2275c..44ccb752 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -296,9 +296,11 @@ module Axlsx def parse_fill_options(options={}) return unless options[:bg_color] color = Color.new(:rgb=>options[:bg_color]) - pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color) + dxf = options[:type] == :dxf + color_key = dxf ? :bgColor : :fgColor + pattern = PatternFill.new(:patternType =>:solid, color_key=>color) fill = Fill.new(pattern) - options[:type] == :dxf ? fill : fills << fill + dxf ? fill : fills << fill end # parses Style#add_style options for borders. -- cgit v1.2.3 From e23558c0bd7bb9027c8ce872ca2b08089b7d1c78 Mon Sep 17 00:00:00 2001 From: Ankur Sethi Date: Sun, 26 May 2013 13:27:31 -0300 Subject: Update test for conditional formatting bg_color --- test/stylesheet/tc_styles.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index b9d0b28a..98c8e3ef 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -150,7 +150,7 @@ class TestStyles < Test::Unit::TestCase assert_equal(@styles.parse_fill_options(:bg_color => "DE").class, Fixnum, "return index of fill if not :dxf type") assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type") f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf) - assert(f.fill_type.fgColor.rgb == "FFDEDEDE") + assert(f.fill_type.bgColor.rgb == "FFDEDEDE") end def test_parse_protection_options @@ -210,7 +210,7 @@ class TestStyles < Test::Unit::TestCase assert_equal(0, style, "returns the zero-based dxfId") dxf = @styles.dxfs.last - assert_equal(@styles.dxfs.last.fill.fill_type.fgColor.rgb, "FF000000", "fill created with color") + assert_equal(@styles.dxfs.last.fill.fill_type.bgColor.rgb, "FF000000", "fill created with color") assert_equal(font_count, (@styles.fonts.size), "font not created under styles") assert_equal(fill_count, (@styles.fills.size), "fill not created under styles") -- cgit v1.2.3