axlsx 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -7
- data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
- data/examples/conditional_formatting/getting_barred.rb +37 -0
- data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
- data/examples/conditional_formatting/scaled_colors.rb +39 -0
- data/examples/conditional_formatting/stop_and_go.rb +37 -0
- data/examples/example.rb +6 -2
- data/examples/{real_example.rb → skydrive/real_example.rb} +0 -0
- data/lib/axlsx.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +16 -0
- data/lib/axlsx/stylesheet/dxf.rb +79 -0
- data/lib/axlsx/stylesheet/font.rb +2 -1
- data/lib/axlsx/stylesheet/styles.rb +141 -50
- data/lib/axlsx/stylesheet/xf.rb +2 -0
- data/lib/axlsx/util/constants.rb +8 -0
- data/lib/axlsx/util/validators.rb +44 -0
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +6 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
- data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb~ +46 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
- data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
- data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb~ +95 -0
- data/lib/axlsx/workbook/worksheet/row.rb +2 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +25 -3
- data/test/drawing/tc_axis.rb +8 -0
- data/test/stylesheet/tc_dxf.rb +81 -0
- data/test/stylesheet/tc_styles.rb +148 -2
- data/test/workbook/worksheet/tc_cfvo.rb +31 -0
- data/test/workbook/worksheet/tc_cfvo.rb~ +20 -0
- data/test/workbook/worksheet/tc_color_scale.rb +29 -0
- data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
- data/test/workbook/worksheet/tc_conditional_formatting.rb +173 -0
- data/test/workbook/worksheet/tc_data_bar.rb +39 -0
- data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
- data/test/workbook/worksheet/tc_icon_set.rb +45 -0
- data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
- data/test/workbook/worksheet/tc_row.rb +9 -2
- metadata +45 -27
- data/examples/axlsx.xlsx +0 -0
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx/util/doc/_index.html +0 -84
- data/lib/axlsx/util/doc/class_list.html +0 -47
- data/lib/axlsx/util/doc/css/common.css +0 -1
- data/lib/axlsx/util/doc/css/full_list.css +0 -55
- data/lib/axlsx/util/doc/css/style.css +0 -322
- data/lib/axlsx/util/doc/file_list.html +0 -46
- data/lib/axlsx/util/doc/frames.html +0 -13
- data/lib/axlsx/util/doc/index.html +0 -84
- data/lib/axlsx/util/doc/js/app.js +0 -205
- data/lib/axlsx/util/doc/js/full_list.js +0 -173
- data/lib/axlsx/util/doc/js/jquery.js +0 -16
- data/lib/axlsx/util/doc/method_list.html +0 -46
- data/lib/axlsx/util/doc/top-level-namespace.html +0 -95
@@ -0,0 +1,46 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# Conditional Format Rule color scale object
|
3
|
+
# Describes a gradated color scale in this conditional formatting rule.
|
4
|
+
|
5
|
+
# @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
|
6
|
+
# @see Worksheet#add_conditional_formatting
|
7
|
+
# @see ConditionalFormattingRule#initialize
|
8
|
+
class ColorScale
|
9
|
+
|
10
|
+
# A simple typed list of cfvos
|
11
|
+
# @return [SimpleTypedList]
|
12
|
+
# @see cfvo
|
13
|
+
attr_reader :cfvos
|
14
|
+
|
15
|
+
# A simple types list of colors
|
16
|
+
# @return [SimpleTypedList]
|
17
|
+
# @see Color
|
18
|
+
attr_reader :colors
|
19
|
+
|
20
|
+
def initializer
|
21
|
+
initialize_cfvos
|
22
|
+
initialize_colors
|
23
|
+
yield self if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
def add
|
27
|
+
@cfvos << Cfvo.new(:type => :min, :val => 0)
|
28
|
+
@colors << Color.new :rgb => "FF000000"
|
29
|
+
{:cfvo => @cfvos.last, :color => @colors.last}
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def initialize_cfvos
|
35
|
+
@cfvos = SimpleTypedList.new Cfvo
|
36
|
+
@cfvos.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
|
37
|
+
@cfvos.lock
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize_colors
|
41
|
+
@colors = SimpleTypedList.new Color
|
42
|
+
@colors.concat [Color.new(:rgb => "FFFF0000", Color.new(:rgb => "FF0000FF")]
|
43
|
+
@colors.lock
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# Conditional formatting allows styling of ranges based on functions
|
3
|
+
#
|
4
|
+
# @note The recommended way to manage conditional formatting is via Worksheet#add_conditional_formatting
|
5
|
+
# @see Worksheet#add_conditional_formatting
|
6
|
+
# @see ConditionalFormattingRule
|
7
|
+
class ConditionalFormatting
|
8
|
+
|
9
|
+
# Range over which the formatting is applied, in "A1:B2" format
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :sqref
|
12
|
+
|
13
|
+
# Rules to apply the formatting to. Can be either a hash of
|
14
|
+
# options to create a {ConditionalFormattingRule}, an array of hashes
|
15
|
+
# for multiple ConditionalFormattingRules, or an array of already
|
16
|
+
# created ConditionalFormattingRules.
|
17
|
+
# @see ConditionalFormattingRule#initialize
|
18
|
+
# @return [Array]
|
19
|
+
attr_reader :rules
|
20
|
+
|
21
|
+
# Creates a new {ConditionalFormatting} object
|
22
|
+
# @option options [Array] rules The rules to apply
|
23
|
+
# @option options [String] sqref The range to apply the rules to
|
24
|
+
def initialize(options={})
|
25
|
+
@rules = []
|
26
|
+
options.each do |o|
|
27
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Add Conditional Formatting Rules to this object. Rules can either
|
32
|
+
# be already created {ConditionalFormattingRule} elements or
|
33
|
+
# hashes of options for automatic creation. If rules is a hash
|
34
|
+
# instead of an array, assume only one rule being added.
|
35
|
+
#
|
36
|
+
# @example This would apply formatting "1" to cells > 20, and formatting "2" to cells < 1
|
37
|
+
# conditional_formatting.add_rules [
|
38
|
+
# { :type => :cellIs, :operator => :greaterThan, :formula => "20", :dxfId => 1, :priority=> 1 },
|
39
|
+
# { :type => :cellIs, :operator => :lessThan, :formula => "10", :dxfId => 2, :priority=> 2 } ]
|
40
|
+
#
|
41
|
+
# @param [Array|Hash] rules the rules to apply, can be just one in hash form
|
42
|
+
# @see ConditionalFormattingRule#initialize
|
43
|
+
def add_rules(rules)
|
44
|
+
rules = [rules] if rules.is_a? Hash
|
45
|
+
rules.each do |rule|
|
46
|
+
add_rule rule
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add a ConditionalFormattingRule. If a hash of options is passed
|
51
|
+
# in create a rule on the fly.
|
52
|
+
# @param [ConditionalFormattingRule|Hash] rule A rule to use, or the options necessary to create one.
|
53
|
+
# @see ConditionalFormattingRule#initialize
|
54
|
+
def add_rule(rule)
|
55
|
+
if rule.is_a? Axlsx::ConditionalFormattingRule
|
56
|
+
@rules << rule
|
57
|
+
elsif rule.is_a? Hash
|
58
|
+
@rules << ConditionalFormattingRule.new(rule)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @see rules
|
63
|
+
def rules=(v); @rules = v end
|
64
|
+
# @see sqref
|
65
|
+
def sqref=(v); Axlsx::validate_string(v); @sqref = v end
|
66
|
+
|
67
|
+
# Serializes the conditional formatting element
|
68
|
+
# @example Conditional Formatting XML looks like:
|
69
|
+
# <conditionalFormatting sqref="E3:E9">
|
70
|
+
# <cfRule type="cellIs" dxfId="0" priority="1" operator="greaterThan">
|
71
|
+
# <formula>0.5</formula>
|
72
|
+
# </cfRule>
|
73
|
+
# </conditionalFormatting>
|
74
|
+
# @param [String] str
|
75
|
+
# @return [String]
|
76
|
+
def to_xml_string(str = '')
|
77
|
+
str << '<conditionalFormatting sqref="' << sqref << '">'
|
78
|
+
str << rules.collect{ |rule| rule.to_xml_string }.join(' ')
|
79
|
+
str << '</conditionalFormatting>'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Axlsx
|
3
|
+
# Conditional formatting rules specify formulas whose evaluations
|
4
|
+
# format cells
|
5
|
+
#
|
6
|
+
# @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
|
7
|
+
# @see Worksheet#add_conditional_formatting
|
8
|
+
# @see ConditionalFormattingRule#initialize
|
9
|
+
class ConditionalFormattingRule
|
10
|
+
|
11
|
+
# instance values that must be serialized as their own elements - e.g. not attributes.
|
12
|
+
CHILD_ELEMENTS = [:formula, :color_scale, :data_bar, :icon_set]
|
13
|
+
|
14
|
+
# Formula
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :formula
|
17
|
+
|
18
|
+
# Type (ST_CfType)
|
19
|
+
# options are expression, cellIs, colorScale, dataBar, iconSet,
|
20
|
+
# top10, uniqueValues, duplicateValues, containsText,
|
21
|
+
# notContainsText, beginsWith, endsWith, containsBlanks,
|
22
|
+
# notContainsBlanks, containsErrors, notContainsErrors,
|
23
|
+
# timePeriod, aboveAverage
|
24
|
+
# @return [Symbol]
|
25
|
+
attr_reader :type
|
26
|
+
|
27
|
+
# Above average rule
|
28
|
+
# Indicates whether the rule is an "above average" rule. True
|
29
|
+
# indicates 'above average'. This attribute is ignored if type is
|
30
|
+
# not equal to aboveAverage.
|
31
|
+
# @return [Boolean]
|
32
|
+
attr_reader :aboveAverage
|
33
|
+
|
34
|
+
# Bottom N rule
|
35
|
+
# @return [Boolean]
|
36
|
+
attr_reader :bottom
|
37
|
+
|
38
|
+
# Differential Formatting Id
|
39
|
+
# @return [Integer]
|
40
|
+
attr_reader :dxfId
|
41
|
+
|
42
|
+
# Equal Average
|
43
|
+
# Flag indicating whether the 'aboveAverage' and 'belowAverage'
|
44
|
+
# criteria is inclusive of the average itself, or exclusive of
|
45
|
+
# that value.
|
46
|
+
# @return [Boolean]
|
47
|
+
attr_reader :equalAverage
|
48
|
+
|
49
|
+
# Operator
|
50
|
+
# The operator in a "cell value is" conditional formatting
|
51
|
+
# rule. This attribute is ignored if type is not equal to cellIs
|
52
|
+
#
|
53
|
+
# Operator must be one of lessThan, lessThanOrEqual, equal,
|
54
|
+
# notEqual, greaterThanOrEqual, greaterThan, between, notBetween,
|
55
|
+
# containsText, notContains, beginsWith, endsWith
|
56
|
+
# @return [Symbol]
|
57
|
+
attr_reader :operator
|
58
|
+
|
59
|
+
# Priority
|
60
|
+
# The priority of this conditional formatting rule. This value is
|
61
|
+
# used to determine which format should be evaluated and
|
62
|
+
# rendered. Lower numeric values are higher priority than higher
|
63
|
+
# numeric values, where '1' is the highest priority.
|
64
|
+
# @return [Integer]
|
65
|
+
attr_reader :priority
|
66
|
+
|
67
|
+
# Text
|
68
|
+
# used in a "text contains" conditional formatting
|
69
|
+
# rule.
|
70
|
+
# @return [String]
|
71
|
+
attr_reader :text
|
72
|
+
|
73
|
+
# percent (Top 10 Percent)
|
74
|
+
# indicates whether a "top/bottom n" rule is a "top/bottom n
|
75
|
+
# percent" rule. This attribute is ignored if type is not equal to
|
76
|
+
# top10.
|
77
|
+
# @return [Boolean]
|
78
|
+
attr_reader :percent
|
79
|
+
|
80
|
+
# rank (Rank)
|
81
|
+
# The value of "n" in a "top/bottom n" conditional formatting
|
82
|
+
# rule. This attribute is ignored if type is not equal to top10.
|
83
|
+
# @return [Integer]
|
84
|
+
attr_reader :rank
|
85
|
+
|
86
|
+
# stdDev (StdDev)
|
87
|
+
# The number of standard deviations to include above or below the
|
88
|
+
# average in the conditional formatting rule. This attribute is
|
89
|
+
# ignored if type is not equal to aboveAverage. If a value is
|
90
|
+
# present for stdDev and the rule type = aboveAverage, then this
|
91
|
+
# rule is automatically an "above or below N standard deviations"
|
92
|
+
# rule.
|
93
|
+
# @return [Integer]
|
94
|
+
attr_reader :stdDev
|
95
|
+
|
96
|
+
# stopIfTrue (Stop If True)
|
97
|
+
# If this flag is '1', no rules with lower priority shall be
|
98
|
+
# applied over this rule, when this rule evaluates to true.
|
99
|
+
# @return [Boolean]
|
100
|
+
attr_reader :stopIfTrue
|
101
|
+
|
102
|
+
# timePeriod (Time Period)
|
103
|
+
# The applicable time period in a "date occurring…" conditional
|
104
|
+
# formatting rule. This attribute is ignored if type is not equal
|
105
|
+
# to timePeriod.
|
106
|
+
# Valid types are today, yesterday, tomorrow, last7Days,
|
107
|
+
# thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
|
108
|
+
attr_reader :timePeriod
|
109
|
+
|
110
|
+
|
111
|
+
# colorScale (Color Scale)
|
112
|
+
# The color scale to apply to this conditional formatting
|
113
|
+
# @return [ColorScale]
|
114
|
+
def color_scale
|
115
|
+
@color_scale ||= ColorScale.new
|
116
|
+
end
|
117
|
+
|
118
|
+
# dataBar (Data Bar)
|
119
|
+
# The data bar to apply to this conditional formatting
|
120
|
+
# @return [DataBar]
|
121
|
+
def data_bar
|
122
|
+
@data_bar ||= DataBar.new
|
123
|
+
end
|
124
|
+
|
125
|
+
# iconSet (Icon Set)
|
126
|
+
# The icon set to apply to this conditional formatting
|
127
|
+
# @return [IconSet]
|
128
|
+
def icon_set
|
129
|
+
@icon_set ||= IconSet.new
|
130
|
+
end
|
131
|
+
|
132
|
+
# Creates a new Conditional Formatting Rule object
|
133
|
+
# @option options [Symbol] type The type of this formatting rule
|
134
|
+
# @option options [Boolean] aboveAverage This is an aboveAverage rule
|
135
|
+
# @option options [Boolean] bottom This is a bottom N rule.
|
136
|
+
# @option options [Integer] dxfId The formatting id to apply to matches
|
137
|
+
# @option options [Boolean] equalAverage Is the aboveAverage or belowAverage rule inclusive
|
138
|
+
# @option options [Integer] priority The priority of the rule, 1 is highest
|
139
|
+
# @option options [Symbol] operator Which operator to apply
|
140
|
+
# @option options [String] text The value to apply a text operator against
|
141
|
+
# @option options [Boolean] percent If a top/bottom N rule, evaluate as N% rather than N
|
142
|
+
# @option options [Integer] rank If a top/bottom N rule, the value of N
|
143
|
+
# @option options [Integer] stdDev The number of standard deviations above or below the average to match
|
144
|
+
# @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
|
145
|
+
# @option options [Symbol] timePeriod The time period in a date occuring... rule
|
146
|
+
# @option options [String] formula The formula to match against in i.e. an equal rule
|
147
|
+
def initialize(options={})
|
148
|
+
@color_scale = @data_bar = @icon_set = @formula = nil
|
149
|
+
options.each do |o|
|
150
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# @see type
|
155
|
+
def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
|
156
|
+
# @see aboveAverage
|
157
|
+
def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
|
158
|
+
# @see bottom
|
159
|
+
def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
|
160
|
+
# @see dxfId
|
161
|
+
def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
|
162
|
+
# @see equalAverage
|
163
|
+
def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
|
164
|
+
# @see priority
|
165
|
+
def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
|
166
|
+
# @see operator
|
167
|
+
def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
|
168
|
+
# @see text
|
169
|
+
def text=(v); Axlsx::validate_string(v); @text = v end
|
170
|
+
# @see percent
|
171
|
+
def percent=(v); Axlsx::validate_boolean(v); @percent = v end
|
172
|
+
# @see rank
|
173
|
+
def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
|
174
|
+
# @see stdDev
|
175
|
+
def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
|
176
|
+
# @see stopIfTrue
|
177
|
+
def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
|
178
|
+
# @see timePeriod
|
179
|
+
def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
|
180
|
+
# @see formula
|
181
|
+
def formula=(v); Axlsx::validate_string(v); @formula = v end
|
182
|
+
|
183
|
+
# @see color_scale
|
184
|
+
def color_scale=(v)
|
185
|
+
Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.color_scale', ColorScale, v
|
186
|
+
@color_scale = v
|
187
|
+
end
|
188
|
+
|
189
|
+
# @see data_bar
|
190
|
+
def data_bar=(v)
|
191
|
+
Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.data_bar', DataBar, v
|
192
|
+
@data_bar = v
|
193
|
+
end
|
194
|
+
|
195
|
+
# @see icon_set
|
196
|
+
def icon_set=(v)
|
197
|
+
Axlsx::DataTypeValidator.validate 'conditional_formatting_rule.icon_set', IconSet, v
|
198
|
+
@icon_set = v
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
# Serializes the conditional formatting rule
|
203
|
+
# @param [String] str
|
204
|
+
# @return [String]
|
205
|
+
def to_xml_string(str = '')
|
206
|
+
str << '<cfRule '
|
207
|
+
str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
|
208
|
+
str << '>'
|
209
|
+
str << '<formula>' << self.formula << '</formula>' if @formula
|
210
|
+
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
|
211
|
+
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
|
212
|
+
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
|
213
|
+
str << '</cfRule>'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# Conditional Format Rule data bar object
|
3
|
+
# Describes a data bar conditional formatting rule.
|
4
|
+
|
5
|
+
# @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
|
6
|
+
# @see Worksheet#add_conditional_formatting
|
7
|
+
# @see ConditionalFormattingRule#initialize
|
8
|
+
class DataBar
|
9
|
+
|
10
|
+
# instance values that must be serialized as their own elements - e.g. not attributes.
|
11
|
+
CHILD_ELEMENTS = [:value_objects, :color]
|
12
|
+
|
13
|
+
# minLength attribute
|
14
|
+
# The minimum length of the data bar, as a percentage of the cell width.
|
15
|
+
# The default value is 10
|
16
|
+
# @return [Integer]
|
17
|
+
attr_reader :minLength
|
18
|
+
|
19
|
+
# maxLength attribute
|
20
|
+
# The maximum length of the data bar, as a percentage of the cell width.
|
21
|
+
# The default value is 90
|
22
|
+
# @return [Integer]
|
23
|
+
attr_reader :maxLength
|
24
|
+
|
25
|
+
# maxLength attribute
|
26
|
+
# Indicates whether to show the values of the cells on which this data bar is applied.
|
27
|
+
# The default value is true
|
28
|
+
# @return [Boolean]
|
29
|
+
attr_reader :showValue
|
30
|
+
|
31
|
+
# A simple typed list of cfvos
|
32
|
+
# @return [SimpleTypedList]
|
33
|
+
# @see Cfvo
|
34
|
+
attr_reader :value_objects
|
35
|
+
|
36
|
+
# color
|
37
|
+
# the color object used in the data bar formatting
|
38
|
+
# @return [Color]
|
39
|
+
def color
|
40
|
+
@color ||= Color.new :rgb => "FF0000FF"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Creates a new data bar conditional formatting object
|
44
|
+
# @option options [Integer] minLength
|
45
|
+
# @option options [Integer] maxLength
|
46
|
+
# @option options [Boolean] showValue
|
47
|
+
# @option options [String] color - the rbg value used to color the bars
|
48
|
+
def initialize(options = {})
|
49
|
+
@minLength = 10
|
50
|
+
@maxLength = 90
|
51
|
+
@showValue = true
|
52
|
+
initialize_value_objects
|
53
|
+
options.each do |o|
|
54
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
55
|
+
end
|
56
|
+
yield self if block_given?
|
57
|
+
end
|
58
|
+
|
59
|
+
# @see minLength
|
60
|
+
def minLength=(v); Axlsx.validate_unsigned_int(v); @minLength = v end
|
61
|
+
# @see maxLength
|
62
|
+
def maxLength=(v); Axlsx.validate_unsigned_int(v); @maxLength = v end
|
63
|
+
|
64
|
+
# @see showValue
|
65
|
+
def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
|
66
|
+
|
67
|
+
# Sets the color for the data bars.
|
68
|
+
# @param [Color|String] The color object, or rgb string value to apply
|
69
|
+
def color=(v)
|
70
|
+
@color = v if v.is_a? Color
|
71
|
+
self.color.rgb = v if v.is_a? String
|
72
|
+
@color
|
73
|
+
end
|
74
|
+
|
75
|
+
# Serialize this object to an xml string
|
76
|
+
# @param [String] str
|
77
|
+
# @return [String]
|
78
|
+
def to_xml_string(str="")
|
79
|
+
str << '<dataBar '
|
80
|
+
str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
|
81
|
+
str << '>'
|
82
|
+
@value_objects.each { |cfvo| cfvo.to_xml_string(str) }
|
83
|
+
self.color.to_xml_string(str)
|
84
|
+
str << '</dataBar>'
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# Initalize the simple typed list of value objects
|
90
|
+
# I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
|
91
|
+
def initialize_value_objects
|
92
|
+
@value_objects = SimpleTypedList.new Cfvo
|
93
|
+
@value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
|
94
|
+
@value_objects.lock
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
File without changes
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# Conditional Format Rule icon sets
|
3
|
+
# Describes an icon set conditional formatting rule.
|
4
|
+
|
5
|
+
# @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
|
6
|
+
# @see Worksheet#add_conditional_formatting
|
7
|
+
# @see ConditionalFormattingRule#initialize
|
8
|
+
class IconSet
|
9
|
+
|
10
|
+
# instance values that must be serialized as their own elements - e.g. not attributes.
|
11
|
+
CHILD_ELEMENTS = [:value_objects]
|
12
|
+
|
13
|
+
# The icon set to display.
|
14
|
+
# Allowed values are: 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights, 5Arrows, 5ArrowsGray, 5Rating, 5Quarters
|
15
|
+
# The default value is 3TrafficLights1
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :iconSet
|
18
|
+
|
19
|
+
# Indicates whether the thresholds indicate percentile values, instead of number values.
|
20
|
+
# The default falue is true
|
21
|
+
# @return [Boolean]
|
22
|
+
attr_reader :percent
|
23
|
+
|
24
|
+
# If true, reverses the default order of the icons in this icon set.maxLength attribute
|
25
|
+
# The default value is false
|
26
|
+
# @return [Boolean]
|
27
|
+
attr_reader :reverse
|
28
|
+
|
29
|
+
# Indicates whether to show the values of the cells on which this data bar is applied.
|
30
|
+
# The default value is true
|
31
|
+
# @return [Boolean]
|
32
|
+
attr_reader :showValue
|
33
|
+
|
34
|
+
# Creates a new icon set object
|
35
|
+
# @option options [String] iconSet
|
36
|
+
# @option options [Boolean] reverse
|
37
|
+
# @option options [Boolean] percent
|
38
|
+
# @option options [Boolean] showValue
|
39
|
+
def initialize(options = {})
|
40
|
+
@percent = @showValue = true
|
41
|
+
@reverse = false
|
42
|
+
@iconSet = "3TrafficLights1"
|
43
|
+
initialize_value_objects
|
44
|
+
options.each do |o|
|
45
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
46
|
+
end
|
47
|
+
yield self if block_given?
|
48
|
+
end
|
49
|
+
|
50
|
+
# @see iconSet
|
51
|
+
def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
|
52
|
+
|
53
|
+
# @see showValue
|
54
|
+
def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
|
55
|
+
|
56
|
+
# @see percent
|
57
|
+
def percent=(v); Axlsx.validate_boolean(v); @percent = v end
|
58
|
+
|
59
|
+
# @see reverse
|
60
|
+
def reverse=(v); Axlsx.validate_boolean(v); @reverse = v end
|
61
|
+
|
62
|
+
# Serialize this object to an xml string
|
63
|
+
# @param [String] str
|
64
|
+
# @return [String]
|
65
|
+
def to_xml_string(str="")
|
66
|
+
str << '<iconSet '
|
67
|
+
str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
|
68
|
+
str << '>'
|
69
|
+
@value_objects.each { |cfvo| cfvo.to_xml_string(str) }
|
70
|
+
str << '</iconSet>'
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Initalize the simple typed list of value objects
|
76
|
+
# I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
|
77
|
+
def initialize_value_objects
|
78
|
+
@value_objects = SimpleTypedList.new Cfvo
|
79
|
+
@value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)]
|
80
|
+
@value_objects.lock
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|