Class: Axlsx::ConditionalFormattingRule

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb

Overview

Note:

The recommended way to manage these rules is via Worksheet#add_conditional_formatting

Conditional formatting rules specify formulas whose evaluations format cells

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ ConditionalFormattingRule

Creates a new Conditional Formatting Rule object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • type (Symbol)

    The type of this formatting rule

  • aboveAverage (Boolean)

    This is an aboveAverage rule

  • bottom (Boolean)

    This is a bottom N rule.

  • dxfId (Integer)

    The formatting id to apply to matches

  • equalAverage (Boolean)

    Is the aboveAverage or belowAverage rule inclusive

  • priority (Integer)

    The priority of the rule, 1 is highest

  • operator (Symbol)

    Which operator to apply

  • text (String)

    The value to apply a text operator against

  • percent (Boolean)

    If a top/bottom N rule, evaluate as N% rather than N

  • rank (Integer)

    If a top/bottom N rule, the value of N

  • stdDev (Integer)

    The number of standard deviations above or below the average to match

  • stopIfTrue (Boolean)

    Stop evaluating rules after this rule matches

  • timePeriod (Symbol)

    The time period in a date occuring... rule

  • formula (String)

    The formula to match against in i.e. an equal rule. Use a [minimum, maximum] array for cellIs between/notBetween conditionals.



27
28
29
30
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 27

def initialize(options = {})
  @color_scale = @data_bar = @icon_set = @formula = nil
  parse_options options
end

Instance Attribute Details

#aboveAverageBoolean

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.

Returns:

  • (Boolean)


56
57
58
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 56

def aboveAverage
  @aboveAverage
end

#bottomBoolean

Bottom N rule

Returns:

  • (Boolean)


60
61
62
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 60

def bottom
  @bottom
end

#dxfIdInteger

Differential Formatting Id

Returns:

  • (Integer)


64
65
66
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 64

def dxfId
  @dxfId
end

#equalAverageBoolean

Equal Average Flag indicating whether the 'aboveAverage' and 'belowAverage' criteria is inclusive of the average itself, or exclusive of that value.

Returns:

  • (Boolean)


71
72
73
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 71

def equalAverage
  @equalAverage
end

#formulaString

Formula The formula or value to match against (e.g. 5 with an operator of :greaterThan to specify cell_value > 5). If the operator is :between or :notBetween, use an array to specify [minimum, maximum]

Returns:

  • (String)


40
41
42
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 40

def formula
  @formula
end

#operatorSymbol

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

Returns:

  • (Symbol)


81
82
83
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 81

def operator
  @operator
end

#percentBoolean

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.

Returns:

  • (Boolean)


102
103
104
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 102

def percent
  @percent
end

#priorityInteger

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.

Returns:

  • (Integer)


89
90
91
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 89

def priority
  @priority
end

#rankInteger

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.

Returns:

  • (Integer)


108
109
110
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 108

def rank
  @rank
end

#stdDevInteger

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.

Returns:

  • (Integer)


118
119
120
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 118

def stdDev
  @stdDev
end

#stopIfTrueBoolean

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.

Returns:

  • (Boolean)


124
125
126
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 124

def stopIfTrue
  @stopIfTrue
end

#textString

Text used in a "text contains" conditional formatting rule.

Returns:

  • (String)


95
96
97
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 95

def text
  @text
end

#timePeriodObject

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



132
133
134
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 132

def timePeriod
  @timePeriod
end

#typeSymbol

Type (ST_CfType) options are expression, cellIs, colorScale, dataBar, iconSet, top10, uniqueValues, duplicateValues, containsText, notContainsText, beginsWith, endsWith, containsBlanks, notContainsBlanks, containsErrors, notContainsErrors, timePeriod, aboveAverage

Returns:

  • (Symbol)


49
50
51
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 49

def type
  @type
end

Instance Method Details

#color_scaleColorScale

colorScale (Color Scale) The color scale to apply to this conditional formatting

Returns:



137
138
139
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 137

def color_scale
  @color_scale ||= ColorScale.new
end

#color_scale=(v) ⇒ Object

See Also:



185
186
187
188
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 185

def color_scale=(v)
  Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.color_scale', ColorScale, v
  @color_scale = v
end

#data_barDataBar

dataBar (Data Bar) The data bar to apply to this conditional formatting

Returns:



144
145
146
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 144

def data_bar
  @data_bar ||= DataBar.new
end

#data_bar=(v) ⇒ Object

See Also:



191
192
193
194
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 191

def data_bar=(v)
  Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.data_bar', DataBar, v
  @data_bar = v
end

#icon_setIconSet

iconSet (Icon Set) The icon set to apply to this conditional formatting

Returns:



151
152
153
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 151

def icon_set
  @icon_set ||= IconSet.new
end

#icon_set=(v) ⇒ Object

See Also:



197
198
199
200
# File 'lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb', line 197

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

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


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 '
  serialized_attributes str
  str << '>'
  str << ('<formula>' << [*self.formula].join('</formula><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