Class: Writexlsx::Package::ConditionalFormat

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/package/conditional_format.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(worksheet, range, param) ⇒ ConditionalFormat


39
40
41
42
# File 'lib/write_xlsx/package/conditional_format.rb', line 39

def initialize(worksheet, range, param)
  @worksheet, @range, @param = worksheet, range, param
  @writer = @worksheet.writer
end

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range


37
38
39
# File 'lib/write_xlsx/package/conditional_format.rb', line 37

def range
  @range
end

Class Method Details

.factory(worksheet, *args) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/write_xlsx/package/conditional_format.rb', line 8

def self.factory(worksheet, *args)
  range, param  =
    Package::ConditionalFormat.new(worksheet, nil, nil).
    range_param_for_conditional_formatting(*args)

  case param[:type]
  when 'cellIs'
    CellIsFormat.new(worksheet, range, param)
  when 'aboveAverage'
    AboveAverageFormat.new(worksheet, range, param)
  when 'top10'
    Top10Format.new(worksheet, range, param)
  when 'containsText', 'notContainsText', 'beginsWith', 'endsWith'
    TextOrWithFormat.new(worksheet, range, param)
  when 'timePeriod'
    TimePeriodFormat.new(worksheet, range, param)
  when 'containsBlanks', 'notContainsBlanks', 'containsErrors', 'notContainsErrors'
    BlanksOrErrorsFormat.new(worksheet, range, param)
  when 'colorScale'
    ColorScaleFormat.new(worksheet, range, param)
  when 'dataBar'
    DataBarFormat.new(worksheet, range, param)
  when 'expression'
    ExpressionFormat.new(worksheet, range, param)
  else # when 'duplicateValues', 'uniqueValues'
    ConditionalFormat.new(worksheet, range, param)
  end
end

Instance Method Details

#attributesObject


69
70
71
72
73
74
75
# File 'lib/write_xlsx/package/conditional_format.rb', line 69

def attributes
  attr = []
  attr << ['type' , type]
  attr << ['dxfId',    format]   if format
  attr << ['priority', priority]
  attr
end

#bar_colorObject


148
149
150
# File 'lib/write_xlsx/package/conditional_format.rb', line 148

def bar_color
  @param[:bar_color]
end

#criteriaObject


89
90
91
# File 'lib/write_xlsx/package/conditional_format.rb', line 89

def criteria
  @param[:criteria]
end

#directionObject


105
106
107
# File 'lib/write_xlsx/package/conditional_format.rb', line 105

def direction
  @param[:direction]
end

#formatObject


81
82
83
# File 'lib/write_xlsx/package/conditional_format.rb', line 81

def format
  @param[:format]
end

#formulaObject


109
110
111
# File 'lib/write_xlsx/package/conditional_format.rb', line 109

def formula
  @param[:formula]
end

#max_colorObject


144
145
146
# File 'lib/write_xlsx/package/conditional_format.rb', line 144

def max_color
  @param[:max_color]
end

#max_typeObject


136
137
138
# File 'lib/write_xlsx/package/conditional_format.rb', line 136

def max_type
  @param[:max_type]
end

#max_valueObject


140
141
142
# File 'lib/write_xlsx/package/conditional_format.rb', line 140

def max_value
  @param[:max_value]
end

#maximumObject


93
94
95
# File 'lib/write_xlsx/package/conditional_format.rb', line 93

def maximum
  @param[:maximum]
end

#mid_colorObject


132
133
134
# File 'lib/write_xlsx/package/conditional_format.rb', line 132

def mid_color
  @param[:mid_color]
end

#mid_typeObject


124
125
126
# File 'lib/write_xlsx/package/conditional_format.rb', line 124

def mid_type
  @param[:mid_type]
end

#mid_valueObject


128
129
130
# File 'lib/write_xlsx/package/conditional_format.rb', line 128

def mid_value
  @param[:mid_value]
end

#min_colorObject


120
121
122
# File 'lib/write_xlsx/package/conditional_format.rb', line 120

def min_color
  @param[:min_color]
end

#min_typeObject


113
114
115
# File 'lib/write_xlsx/package/conditional_format.rb', line 113

def min_type
  @param[:min_type]
end

#min_valueObject


116
117
118
# File 'lib/write_xlsx/package/conditional_format.rb', line 116

def min_value
  @param[:min_value]
end

#minimumObject


97
98
99
# File 'lib/write_xlsx/package/conditional_format.rb', line 97

def minimum
  @param[:minimum]
end

#priorityObject


85
86
87
# File 'lib/write_xlsx/package/conditional_format.rb', line 85

def priority
  @param[:priority]
end

#range_param_for_conditional_formatting(*args) ⇒ Object

:nodoc:


152
153
154
155
156
157
158
159
160
161
# File 'lib/write_xlsx/package/conditional_format.rb', line 152

def range_param_for_conditional_formatting(*args)  # :nodoc:
  range_start_cell_for_conditional_formatting(*args)
  param_for_conditional_formatting(*args)

  handling_of_text_criteria        if @param[:type] == 'text'
  handling_of_time_period_criteria if @param[:type] == 'timePeriod'
  handling_of_blanks_error_types

  [@range, @param]
end

#typeObject


77
78
79
# File 'lib/write_xlsx/package/conditional_format.rb', line 77

def type
  @param[:type]
end

#valueObject


101
102
103
# File 'lib/write_xlsx/package/conditional_format.rb', line 101

def value
  @param[:value]
end

#write_cf_ruleObject


44
45
46
# File 'lib/write_xlsx/package/conditional_format.rb', line 44

def write_cf_rule
  @writer.empty_tag('cfRule', attributes)
end

#write_cf_rule_formula_tag(tag = formula) ⇒ Object


48
49
50
51
52
# File 'lib/write_xlsx/package/conditional_format.rb', line 48

def write_cf_rule_formula_tag(tag = formula)
  @writer.tag_elements('cfRule', attributes) do
    write_formula_tag(tag)
  end
end

#write_cfvo(type, val) ⇒ Object

Write the <cfvo> element.


62
63
64
65
66
67
# File 'lib/write_xlsx/package/conditional_format.rb', line 62

def write_cfvo(type, val)
  @writer.empty_tag('cfvo', [
                             ['type', type],
                             ['val', val]
                            ])
end

#write_formula_tag(data) ⇒ Object

:nodoc:


54
55
56
57
# File 'lib/write_xlsx/package/conditional_format.rb', line 54

def write_formula_tag(data) #:nodoc:
  data = data.sub(/^=/, '') if data.respond_to?(:sub)
  @writer.data_element('formula', data)
end