Class: Axlsx::ConditionalFormattingRule
- Inherits:
-
Object
- Object
- Axlsx::ConditionalFormattingRule
- Defined in:
- lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
Overview
The recommended way to manage these rules is via Worksheet#add_conditional_formatting
Conditional formatting rules specify formulas whose evaluations format cells
Constant Summary collapse
- CHILD_ELEMENTS =
instance values that must be serialized as their own elements - e.g. not attributes.
[:formula, :color_scale, :data_bar, :icon_set]
Instance Attribute Summary collapse
-
#aboveAverage ⇒ Boolean
Above average rule Indicates whether the rule is an "above average" rule.
-
#bottom ⇒ Boolean
Bottom N rule.
-
#dxfId ⇒ Integer
Differential Formatting Id.
-
#equalAverage ⇒ Boolean
Equal Average Flag indicating whether the 'aboveAverage' and 'belowAverage' criteria is inclusive of the average itself, or exclusive of that value.
-
#formula ⇒ String
Formula.
-
#operator ⇒ Symbol
Operator The operator in a "cell value is" conditional formatting rule.
-
#percent ⇒ Boolean
percent (Top 10 Percent) indicates whether a "top/bottom n" rule is a "top/bottom n percent" rule.
-
#priority ⇒ Integer
Priority The priority of this conditional formatting rule.
-
#rank ⇒ Integer
rank (Rank) The value of "n" in a "top/bottom n" conditional formatting rule.
-
#stdDev ⇒ Integer
stdDev (StdDev) The number of standard deviations to include above or below the average in the conditional formatting rule.
-
#stopIfTrue ⇒ Boolean
stopIfTrue (Stop If True) If this flag is '1', no rules with lower priority shall be applied over this rule, when this rule evaluates to true.
-
#text ⇒ String
Text used in a "text contains" conditional formatting rule.
-
#timePeriod ⇒ Object
timePeriod (Time Period) The applicable time period in a "date occurring…" conditional formatting rule.
-
#type ⇒ Symbol
Type (ST_CfType) options are expression, cellIs, colorScale, dataBar, iconSet, top10, uniqueValues, duplicateValues, containsText, notContainsText, beginsWith, endsWith, containsBlanks, notContainsBlanks, containsErrors, notContainsErrors, timePeriod, aboveAverage.
Instance Method Summary collapse
-
#color_scale ⇒ ColorScale
colorScale (Color Scale) The color scale to apply to this conditional formatting.
- #color_scale=(v) ⇒ Object
-
#data_bar ⇒ DataBar
dataBar (Data Bar) The data bar to apply to this conditional formatting.
- #data_bar=(v) ⇒ Object
-
#icon_set ⇒ IconSet
iconSet (Icon Set) The icon set to apply to this conditional formatting.
- #icon_set=(v) ⇒ Object
-
#initialize(options = {}) ⇒ ConditionalFormattingRule
constructor
Creates a new Conditional Formatting Rule object.
-
#to_xml_string(str = '') ⇒ String
Serializes the conditional formatting rule.
Constructor Details
#initialize(options = {}) ⇒ ConditionalFormattingRule
Creates a new Conditional Formatting Rule object
147 148 149 150 151 152 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 147 def initialize(={}) @color_scale = @data_bar = @icon_set = @formula = nil .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end end |
Instance Attribute Details
#aboveAverage ⇒ Boolean
Above average rule Indicates whether the rule is an "above average" rule. True indicates 'above average'. This attribute is ignored if type is not equal to aboveAverage.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 32 def aboveAverage @aboveAverage end |
#bottom ⇒ Boolean
Bottom N rule
36 37 38 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 36 def bottom @bottom end |
#dxfId ⇒ Integer
Differential Formatting Id
40 41 42 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 40 def dxfId @dxfId end |
#equalAverage ⇒ Boolean
Equal Average Flag indicating whether the 'aboveAverage' and 'belowAverage' criteria is inclusive of the average itself, or exclusive of that value.
47 48 49 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 47 def equalAverage @equalAverage end |
#formula ⇒ String
Formula
16 17 18 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 16 def formula @formula end |
#operator ⇒ Symbol
Operator The operator in a "cell value is" conditional formatting rule. This attribute is ignored if type is not equal to cellIs
Operator must be one of lessThan, lessThanOrEqual, equal, notEqual, greaterThanOrEqual, greaterThan, between, notBetween, containsText, notContains, beginsWith, endsWith
57 58 59 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 57 def operator @operator end |
#percent ⇒ Boolean
percent (Top 10 Percent) indicates whether a "top/bottom n" rule is a "top/bottom n percent" rule. This attribute is ignored if type is not equal to top10.
78 79 80 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 78 def percent @percent end |
#priority ⇒ Integer
Priority The priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where '1' is the highest priority.
65 66 67 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 65 def priority @priority end |
#rank ⇒ Integer
rank (Rank) The value of "n" in a "top/bottom n" conditional formatting rule. This attribute is ignored if type is not equal to top10.
84 85 86 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 84 def rank @rank end |
#stdDev ⇒ Integer
stdDev (StdDev) The number of standard deviations to include above or below the average in the conditional formatting rule. This attribute is ignored if type is not equal to aboveAverage. If a value is present for stdDev and the rule type = aboveAverage, then this rule is automatically an "above or below N standard deviations" rule.
94 95 96 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 94 def stdDev @stdDev end |
#stopIfTrue ⇒ Boolean
stopIfTrue (Stop If True) If this flag is '1', no rules with lower priority shall be applied over this rule, when this rule evaluates to true.
100 101 102 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 100 def stopIfTrue @stopIfTrue end |
#text ⇒ String
Text used in a "text contains" conditional formatting rule.
71 72 73 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 71 def text @text end |
#timePeriod ⇒ Object
timePeriod (Time Period) The applicable time period in a "date occurring…" conditional formatting rule. This attribute is ignored if type is not equal to timePeriod. Valid types are today, yesterday, tomorrow, last7Days, thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
108 109 110 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 108 def timePeriod @timePeriod end |
#type ⇒ Symbol
Type (ST_CfType) options are expression, cellIs, colorScale, dataBar, iconSet, top10, uniqueValues, duplicateValues, containsText, notContainsText, beginsWith, endsWith, containsBlanks, notContainsBlanks, containsErrors, notContainsErrors, timePeriod, aboveAverage
25 26 27 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 25 def type @type end |
Instance Method Details
#color_scale ⇒ ColorScale
colorScale (Color Scale) The color scale to apply to this conditional formatting
114 115 116 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 114 def color_scale @color_scale ||= ColorScale.new end |
#color_scale=(v) ⇒ Object
184 185 186 187 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 184 def color_scale=(v) Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.color_scale', ColorScale, v @color_scale = v end |
#data_bar ⇒ DataBar
dataBar (Data Bar) The data bar to apply to this conditional formatting
121 122 123 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 121 def @data_bar ||= DataBar.new end |
#data_bar=(v) ⇒ Object
190 191 192 193 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 190 def (v) Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.data_bar', DataBar, v @data_bar = v end |
#icon_set ⇒ IconSet
iconSet (Icon Set) The icon set to apply to this conditional formatting
128 129 130 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 128 def icon_set @icon_set ||= IconSet.new end |
#icon_set=(v) ⇒ Object
196 197 198 199 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 196 def icon_set=(v) Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.icon_set', IconSet, v @icon_set = v end |
#to_xml_string(str = '') ⇒ String
Serializes the conditional formatting rule
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 205 def to_xml_string(str = '') str << '<cfRule ' str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ') str << '>' str << '<formula>' << self.formula << '</formula>' if @formula @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet str << '</cfRule>' end |