class Xlsxrb::Ooxml::Reader::ConditionalFormattingListener
SAX2 listener for parsing conditionalFormatting elements.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 3788 def initialize @rules = [] @current_sqref = nil @current_pivot = false @current_rule = nil @inside_formula = false @text_buffer = +"" @cfvo_target = nil @color_target = nil end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 3871 def characters(text) @text_buffer << text if @inside_formula end
# File lib/xlsxrb/ooxml/reader.rb, line 3875 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) case name when "formula" (@current_rule[:formulas] ||= []) << @text_buffer.dup if @current_rule @inside_formula = false when "cfRule" @rules << @current_rule if @current_rule @current_rule = nil when "conditionalFormatting" @current_sqref = nil when "colorScale", "dataBar", "iconSet" @cfvo_target = nil @color_target = nil end end
# File lib/xlsxrb/ooxml/reader.rb, line 3799 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "conditionalFormatting" @current_sqref = attributes["sqref"] @current_pivot = attributes["pivot"] == "1" when "cfRule" @current_rule = { sqref: @current_sqref, type: attributes["type"] } @current_rule[:pivot] = true if @current_pivot @current_rule[:priority] = attributes["priority"].to_i if attributes["priority"] @current_rule[:operator] = attributes["operator"] if attributes["operator"] @current_rule[:format_id] = attributes["dxfId"].to_i if attributes["dxfId"] @current_rule[:stop_if_true] = true if attributes["stopIfTrue"] == "1" @current_rule[:above_average] = false if attributes["aboveAverage"] == "0" @current_rule[:equal_average] = true if attributes["equalAverage"] == "1" @current_rule[:rank] = attributes["rank"].to_i if attributes["rank"] @current_rule[:percent] = true if attributes["percent"] == "1" @current_rule[:bottom] = true if attributes["bottom"] == "1" @current_rule[:text] = attributes["text"] if attributes["text"] @current_rule[:time_period] = attributes["timePeriod"] if attributes["timePeriod"] sd = attributes["stdDev"] @current_rule[:std_dev] = sd.to_i if sd when "formula" @inside_formula = true @text_buffer = +"" when "colorScale" @current_rule[:color_scale] = { cfvo: [], colors: [] } if @current_rule @cfvo_target = :color_scale @color_target = :color_scale when "dataBar" if @current_rule db = { cfvo: [] } db[:min_length] = attributes["minLength"].to_i if attributes["minLength"] db[:max_length] = attributes["maxLength"].to_i if attributes["maxLength"] sv = attributes["showValue"] db[:show_value] = %w[1 true].include?(sv) unless sv.nil? @current_rule[:data_bar] = db end @cfvo_target = :data_bar @color_target = :data_bar when "iconSet" if @current_rule is = { cfvo: [] } is[:icon_set] = attributes["iconSet"] if attributes["iconSet"] rv = attributes["reverse"] is[:reverse] = %w[1 true].include?(rv) unless rv.nil? pct = attributes["percent"] is[:percent] = %w[1 true].include?(pct) unless pct.nil? sv = attributes["showValue"] is[:show_value] = %w[1 true].include?(sv) unless sv.nil? @current_rule[:icon_set] = is end @cfvo_target = :icon_set when "cfvo" cfvo = { type: attributes["type"] } cfvo[:val] = attributes["val"] if attributes["val"] gte = attributes["gte"] cfvo[:gte] = %w[1 true].include?(gte) unless gte.nil? append_cfvo(cfvo) when "color" if attributes["rgb"] append_cf_color({ rgb: attributes["rgb"] }) elsif attributes["theme"] c = { theme: attributes["theme"].to_i } c[:tint] = attributes["tint"].to_f if attributes["tint"] append_cf_color(c) elsif attributes["indexed"] append_cf_color({ indexed: attributes["indexed"].to_i }) end end end