class Axlsx::ConditionalFormattingRule

Conditional formatting rules specify formulas whose evaluations format cells

@note The recommended way to manage these rules is via Worksheet#add_conditional_formatting @see Worksheet#add_conditional_formatting @see ConditionalFormattingRule#initialize

Attributes

aboveAverage[R]

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. @return [Boolean]

bottom[R]

Bottom N rule @return [Boolean]

dxfId[R]

Differential Formatting Id @return [Integer]

equalAverage[R]

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

formula[R]

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] @return [String]

operator[R]

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 @return [Symbol]

percent[R]

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. @return [Boolean]

priority[R]

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. @return [Integer]

rank[R]

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. @return [Integer]

stdDev[R]

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. @return [Integer]

stopIfTrue[R]

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. @return [Boolean]

text[R]

Text used in a “text contains” conditional formatting rule. @return [String]

timePeriod[R]

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

type[R]

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

Public Class Methods

new(options={}) click to toggle source

Creates a new Conditional Formatting Rule object @option options [Symbol] type The type of this formatting rule @option options [Boolean] aboveAverage This is an aboveAverage rule @option options [Boolean] bottom This is a bottom N rule. @option options [Integer] dxfId The formatting id to apply to matches @option options [Boolean] equalAverage Is the aboveAverage or belowAverage rule inclusive @option options [Integer] priority The priority of the rule, 1 is highest @option options [Symbol] operator Which operator to apply @option options [String] text The value to apply a text operator against @option options [Boolean] percent If a top/bottom N rule, evaluate as N% rather than N @option options [Integer] rank If a top/bottom N rule, the value of N @option options [Integer] stdDev The number of standard deviations above or below the average to match @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches @option options [Symbol] timePeriod The time period in a date occuring… rule @option options [String] formula The formula to match against in i.e. an equal rule. Use a [minimum, maximum] array for cellIs between/notBetween conditionals.

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 28
def initialize(options={})
  @color_scale = @data_bar = @icon_set = @formula = nil
  parse_options options
end

Public Instance Methods

aboveAverage=(v) click to toggle source

@see aboveAverage

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 160
def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
bottom=(v) click to toggle source

@see bottom

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 162
def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
color_scale() click to toggle source

colorScale (Color Scale) The color scale to apply to this conditional formatting @return [ColorScale]

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 139
def color_scale
  @color_scale ||= ColorScale.new
end
color_scale=(v) click to toggle source

@see color_scale

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 187
def color_scale=(v)
  Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.color_scale', ColorScale, v
  @color_scale = v
end
data_bar() click to toggle source

dataBar (Data Bar) The data bar to apply to this conditional formatting @return [DataBar]

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 146
def data_bar
  @data_bar ||= DataBar.new
end
data_bar=(v) click to toggle source

@see data_bar

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 193
def data_bar=(v)
  Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.data_bar', DataBar, v
  @data_bar = v
end
dxfId=(v) click to toggle source

@see dxfId

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 164
def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
equalAverage=(v) click to toggle source

@see equalAverage

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 166
def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
formula=(v) click to toggle source

@see formula

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 184
def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
icon_set() click to toggle source

iconSet (Icon Set) The icon set to apply to this conditional formatting @return [IconSet]

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 153
def icon_set
  @icon_set ||= IconSet.new
end
icon_set=(v) click to toggle source

@see icon_set

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 199
def icon_set=(v)
  Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.icon_set', IconSet, v
  @icon_set = v
end
operator=(v) click to toggle source

@see operator

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 170
def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
percent=(v) click to toggle source

@see percent

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 174
def percent=(v); Axlsx::validate_boolean(v); @percent = v end
priority=(v) click to toggle source

@see priority

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 168
def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
rank=(v) click to toggle source

@see rank

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 176
def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
stdDev=(v) click to toggle source

@see stdDev

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 178
def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
stopIfTrue=(v) click to toggle source

@see stopIfTrue

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 180
def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
text=(v) click to toggle source

@see text

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 172
def text=(v); Axlsx::validate_string(v); @text = v end
timePeriod=(v) click to toggle source

@see timePeriod

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 182
def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
to_xml_string(str = '') click to toggle source

Serializes the conditional formatting rule @param [String] str @return [String]

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 208
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
type=(v) click to toggle source

@see type

# File lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb, line 158
def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end