From 8910b0ae5baa4e6371352bd4eac237fb3e7b10a4 Mon Sep 17 00:00:00 2001 From: Stephen Pike Date: Sat, 21 Apr 2012 09:33:49 -0400 Subject: Update icon_set to use percent in its value_objects Extend conditional formatting to the entire examples Rename example file to "example_conditional_formatting.xls" --- examples/example_conditional_formatting.rb | 18 +++++++++--------- lib/axlsx/workbook/worksheet/icon_set.rb | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/example_conditional_formatting.rb b/examples/example_conditional_formatting.rb index 429b6fac..ab49d238 100644 --- a/examples/example_conditional_formatting.rb +++ b/examples/example_conditional_formatting.rb @@ -25,8 +25,8 @@ book.add_worksheet(:name => "Cell Is") do |ws| ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] end -# Apply conditional formatting to range B4:B100 in the worksheet - ws.add_conditional_formatting("B4:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 }) +# Apply conditional formatting to range B3:B100 in the worksheet + ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 }) end book.add_worksheet(:name => "Color Scale") do |ws| @@ -37,9 +37,9 @@ book.add_worksheet(:name => "Color Scale") do |ws| offset.upto(rows + offset) do |i| ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] end -# Apply conditional formatting to range B4:B100 in the worksheet +# Apply conditional formatting to range B3:B100 in the worksheet color_scale = Axlsx::ColorScale.new - ws.add_conditional_formatting("B4:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale }) + ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale }) end @@ -51,9 +51,9 @@ book.add_worksheet(:name => "Data Bar") do |ws| offset.upto(rows + offset) do |i| ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] end -# Apply conditional formatting to range B4:B100 in the worksheet +# Apply conditional formatting to range B3:B100 in the worksheet data_bar = Axlsx::DataBar.new - ws.add_conditional_formatting("B4:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar }) + ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar }) end book.add_worksheet(:name => "Icon Set") do |ws| @@ -64,9 +64,9 @@ book.add_worksheet(:name => "Icon Set") do |ws| offset.upto(rows + offset) do |i| ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] end -# Apply conditional formatting to range B4:B100 in the worksheet +# Apply conditional formatting to range B3:B100 in the worksheet icon_set = Axlsx::IconSet.new - ws.add_conditional_formatting("B4:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) + ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) end -p.serialize('example_differential_styling.xlsx') +p.serialize('example_conditional_formatting.xlsx') diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb index 7ec94088..68f217da 100644 --- a/lib/axlsx/workbook/worksheet/icon_set.rb +++ b/lib/axlsx/workbook/worksheet/icon_set.rb @@ -74,7 +74,7 @@ module Axlsx # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do. def initialize_value_objects @value_objects = SimpleTypedList.new Cfvo - @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)] + @value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)] @value_objects.lock end end -- cgit v1.2.3 From a86acda991fda771ebc41011f9d7895bf46c8c1d Mon Sep 17 00:00:00 2001 From: Stephen Pike Date: Sat, 21 Apr 2012 09:35:13 -0400 Subject: Update conditional formatting tests to account for 3 cfvo objs in icon sets --- test/workbook/worksheet/tc_conditional_formatting.rb | 2 +- test/workbook/worksheet/tc_icon_set.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb index 0dcb1a7c..6b2c6c3b 100644 --- a/test/workbook/worksheet/tc_conditional_formatting.rb +++ b/test/workbook/worksheet/tc_conditional_formatting.rb @@ -51,7 +51,7 @@ class TestConditionalFormatting < Test::Unit::TestCase cfs.last.rules.last.type = :iconSet doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 2) + assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 3) assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size, 1) end diff --git a/test/workbook/worksheet/tc_icon_set.rb b/test/workbook/worksheet/tc_icon_set.rb index bb90276c..5c442068 100644 --- a/test/workbook/worksheet/tc_icon_set.rb +++ b/test/workbook/worksheet/tc_icon_set.rb @@ -39,7 +39,7 @@ class TestIconSet < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML.parse(@icon_set.to_xml_string) assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent='true'][@reverse='false'][@showValue='true']").size, 1) - assert_equal(doc.xpath(".//iconSet//cfvo").size, 2) + assert_equal(doc.xpath(".//iconSet//cfvo").size, 3) end end -- cgit v1.2.3