class Axlsx::ConditionalFormatting

The recommended way to manage conditional formatting is via Worksheet#add_conditional_formatting

Conditional formatting allows styling of ranges based on functions

Creates a new Axlsx::ConditionalFormatting object


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

    a customizable set of options

Options Hash (options):

  • rules (Array)

    The rules to apply

  • sqref (String)

    The range to apply the rules to

Add a ConditionalFormattingRule. If a hash of options is passed in create a rule on the fly.


  • rule (ConditionalFormattingRule|Hash)

    A rule to use, or the options necessary to create one.

be already created Axlsx::ConditionalFormattingRule elements or hashes of options for automatic creation. If rules is a hash instead of an array, assume only one rule being added.


This would apply formatting “1” to cells > 20, and formatting “2” to cells < 1

conditional_formatting.add_rules [
    { :type => :cellIs, :operator => :greaterThan, :formula => "20", :dxfId => 1, :priority=> 1 },
    { :type => :cellIs, :operator => :lessThan, :formula => "10", :dxfId => 2, :priority=> 2 } ]


  • rules (Array|Hash)

    the rules to apply, can be just one in hash form

Rules to apply the formatting to. Can be either a hash of options to create a Axlsx::ConditionalFormattingRule, an array of hashes for multiple ConditionalFormattingRules, or an array of already created ConditionalFormattingRules.

Range over which the formatting is applied, in “A1:B2” format

Serializes the conditional formatting element


Conditional Formatting XML looks like:

<conditionalFormatting sqref="E3:E9">
    <cfRule type="cellIs" dxfId="0" priority="1" operator="greaterThan">


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

ConditionalFormatting is referenced in 0 repositories