caxlsx 4.0.0 → 4.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -12
- data/README.md +1 -1
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +6 -3
- data/lib/axlsx/content_type/content_type.rb +4 -4
- data/lib/axlsx/content_type/default.rb +4 -1
- data/lib/axlsx/content_type/override.rb +4 -1
- data/lib/axlsx/doc_props/app.rb +91 -24
- data/lib/axlsx/drawing/area_chart.rb +3 -3
- data/lib/axlsx/drawing/area_series.rb +10 -4
- data/lib/axlsx/drawing/ax_data_source.rb +1 -1
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +25 -7
- data/lib/axlsx/drawing/bar_3D_chart.rb +3 -3
- data/lib/axlsx/drawing/bar_chart.rb +3 -3
- data/lib/axlsx/drawing/bar_series.rb +14 -5
- data/lib/axlsx/drawing/bubble_chart.rb +2 -2
- data/lib/axlsx/drawing/bubble_series.rb +2 -2
- data/lib/axlsx/drawing/cat_axis.rb +23 -8
- data/lib/axlsx/drawing/chart.rb +32 -8
- data/lib/axlsx/drawing/d_lbls.rb +8 -8
- data/lib/axlsx/drawing/drawing.rb +50 -49
- data/lib/axlsx/drawing/hyperlink.rb +13 -4
- data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
- data/lib/axlsx/drawing/line_chart.rb +3 -3
- data/lib/axlsx/drawing/line_series.rb +10 -4
- data/lib/axlsx/drawing/marker.rb +19 -4
- data/lib/axlsx/drawing/num_val.rb +1 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +8 -2
- data/lib/axlsx/drawing/pic.rb +17 -8
- data/lib/axlsx/drawing/pie_3D_chart.rb +3 -3
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +18 -6
- data/lib/axlsx/drawing/scaling.rb +18 -4
- data/lib/axlsx/drawing/scatter_chart.rb +2 -2
- data/lib/axlsx/drawing/scatter_series.rb +2 -2
- data/lib/axlsx/drawing/ser_axis.rb +11 -5
- data/lib/axlsx/drawing/series.rb +8 -2
- data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
- data/lib/axlsx/drawing/val_axis.rb +2 -2
- data/lib/axlsx/drawing/view_3D.rb +8 -2
- data/lib/axlsx/package.rb +11 -11
- data/lib/axlsx/rels/relationship.rb +15 -5
- data/lib/axlsx/rels/relationships.rb +3 -3
- data/lib/axlsx/stylesheet/border.rb +12 -3
- data/lib/axlsx/stylesheet/border_pr.rb +15 -4
- data/lib/axlsx/stylesheet/cell_alignment.rb +39 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +9 -2
- data/lib/axlsx/stylesheet/cell_style.rb +30 -7
- data/lib/axlsx/stylesheet/color.rb +10 -4
- data/lib/axlsx/stylesheet/dxf.rb +29 -6
- data/lib/axlsx/stylesheet/fill.rb +4 -1
- data/lib/axlsx/stylesheet/font.rb +59 -13
- data/lib/axlsx/stylesheet/gradient_fill.rb +9 -3
- data/lib/axlsx/stylesheet/gradient_stop.rb +9 -2
- data/lib/axlsx/stylesheet/num_fmt.rb +8 -2
- data/lib/axlsx/stylesheet/pattern_fill.rb +14 -3
- data/lib/axlsx/stylesheet/styles.rb +83 -43
- data/lib/axlsx/stylesheet/table_style.rb +15 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +12 -3
- data/lib/axlsx/stylesheet/table_styles.rb +10 -3
- data/lib/axlsx/stylesheet/xf.rb +69 -16
- data/lib/axlsx/util/accessors.rb +9 -7
- data/lib/axlsx/util/constants.rb +2 -2
- data/lib/axlsx/util/serialized_attributes.rb +2 -2
- data/lib/axlsx/util/simple_typed_list.rb +25 -12
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/validators.rb +1 -1
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +1 -1
- data/lib/axlsx/workbook/defined_names.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
- data/lib/axlsx/workbook/workbook.rb +80 -67
- data/lib/axlsx/workbook/workbook_views.rb +1 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +5 -3
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +3 -3
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
- data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
- data/lib/axlsx/workbook/worksheet/cell.rb +37 -17
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
- data/lib/axlsx/workbook/worksheet/cfvo.rb +8 -2
- data/lib/axlsx/workbook/worksheet/col.rb +22 -9
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +1 -1
- data/lib/axlsx/workbook/worksheet/cols.rb +1 -1
- data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
- data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -3
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +70 -15
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -3
- data/lib/axlsx/workbook/worksheet/data_validation.rb +53 -14
- data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -3
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
- data/lib/axlsx/workbook/worksheet/icon_set.rb +17 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +1 -1
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_margins.rb +30 -7
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -2
- data/lib/axlsx/workbook/worksheet/page_setup.rb +32 -9
- data/lib/axlsx/workbook/worksheet/pane.rb +8 -2
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +29 -5
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +31 -11
- data/lib/axlsx/workbook/worksheet/row.rb +5 -2
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +1 -1
- data/lib/axlsx/workbook/worksheet/selection.rb +8 -2
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -1
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +30 -9
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -2
- data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +28 -14
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +3 -3
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +2 -2
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +2 -2
- data/lib/axlsx.rb +44 -30
- data/lib/caxlsx.rb +1 -1
- metadata +10 -48
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative 'sort_condition'
|
|
4
4
|
|
|
5
5
|
module Axlsx
|
|
6
6
|
# This class performs sorting on a range in a worksheet
|
|
@@ -21,7 +21,7 @@ module Axlsx
|
|
|
21
21
|
# It requires a column_index for the sorting, descending and the custom order are optional.
|
|
22
22
|
# @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
|
|
23
23
|
# @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
|
|
24
|
-
# @param [Array] custom_list An array
|
|
24
|
+
# @param [Array] custom_list An array containing a custom sorting list in order.
|
|
25
25
|
# @return [SortCondition]
|
|
26
26
|
def add_sort_condition(column_index:, order: :asc, custom_list: [])
|
|
27
27
|
sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
|
|
@@ -63,19 +63,19 @@ module Axlsx
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def first_row
|
|
66
|
-
@first_row ||= first_cell
|
|
66
|
+
@first_row ||= first_cell[/\d+/]
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
def first_col
|
|
70
|
-
@first_col ||= first_cell
|
|
70
|
+
@first_col ||= first_cell[/\D+/]
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def last_row
|
|
74
|
-
@last_row ||= last_cell
|
|
74
|
+
@last_row ||= last_cell[/\d+/]
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def last_col
|
|
78
|
-
@last_col ||= last_cell
|
|
78
|
+
@last_col ||= last_cell[/\D+/]
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Axlsx
|
|
4
4
|
# A cell in a worksheet.
|
|
5
|
-
# Cell stores
|
|
5
|
+
# Cell stores information required to serialize a single worksheet cell to xml. You must provide the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
|
|
6
6
|
# @note The recommended way to generate cells is via Worksheet#add_row
|
|
7
7
|
#
|
|
8
8
|
# @see Worksheet#add_row
|
|
@@ -41,7 +41,7 @@ module Axlsx
|
|
|
41
41
|
self.type = type unless type == :string
|
|
42
42
|
|
|
43
43
|
val = options.delete(:style)
|
|
44
|
-
self.style = val unless val.nil? || val
|
|
44
|
+
self.style = val unless val.nil? || val == 0
|
|
45
45
|
val = options.delete(:formula_value)
|
|
46
46
|
self.formula_value = val unless val.nil?
|
|
47
47
|
val = options.delete(:escape_formulas)
|
|
@@ -57,11 +57,11 @@ module Axlsx
|
|
|
57
57
|
# you need to set this.
|
|
58
58
|
attr_accessor :formula_value
|
|
59
59
|
|
|
60
|
-
# An array of available inline
|
|
60
|
+
# An array of available inline styles.
|
|
61
61
|
# TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
|
|
62
|
-
# then move it out to a module so we can
|
|
62
|
+
# then move it out to a module so we can reuse in in other classes.
|
|
63
63
|
# needs to define bla=(v) and bla methods on the class that hook into a
|
|
64
|
-
# set_attr method that kicks the
|
|
64
|
+
# set_attr method that kicks the supplied validator and updates the instance_variable
|
|
65
65
|
# for the key
|
|
66
66
|
INLINE_STYLES = [:value, :type, :font_name, :charset,
|
|
67
67
|
:family, :b, :i, :strike, :outline,
|
|
@@ -189,7 +189,9 @@ module Axlsx
|
|
|
189
189
|
attr_reader :font_name
|
|
190
190
|
|
|
191
191
|
# @see font_name
|
|
192
|
-
def font_name=(v)
|
|
192
|
+
def font_name=(v)
|
|
193
|
+
set_run_style :validate_string, :font_name, v
|
|
194
|
+
end
|
|
193
195
|
|
|
194
196
|
# The inline charset property for the cell
|
|
195
197
|
# As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
|
|
@@ -216,7 +218,9 @@ module Axlsx
|
|
|
216
218
|
attr_reader :charset
|
|
217
219
|
|
|
218
220
|
# @see charset
|
|
219
|
-
def charset=(v)
|
|
221
|
+
def charset=(v)
|
|
222
|
+
set_run_style :validate_unsigned_int, :charset, v
|
|
223
|
+
end
|
|
220
224
|
|
|
221
225
|
# The inline family property for the cell
|
|
222
226
|
# @return [Integer]
|
|
@@ -237,49 +241,63 @@ module Axlsx
|
|
|
237
241
|
attr_reader :b
|
|
238
242
|
|
|
239
243
|
# @see b
|
|
240
|
-
def b=(v)
|
|
244
|
+
def b=(v)
|
|
245
|
+
set_run_style :validate_boolean, :b, v
|
|
246
|
+
end
|
|
241
247
|
|
|
242
248
|
# The inline italic property for the cell
|
|
243
249
|
# @return [Boolean]
|
|
244
250
|
attr_reader :i
|
|
245
251
|
|
|
246
252
|
# @see i
|
|
247
|
-
def i=(v)
|
|
253
|
+
def i=(v)
|
|
254
|
+
set_run_style :validate_boolean, :i, v
|
|
255
|
+
end
|
|
248
256
|
|
|
249
257
|
# The inline strike property for the cell
|
|
250
258
|
# @return [Boolean]
|
|
251
259
|
attr_reader :strike
|
|
252
260
|
|
|
253
261
|
# @see strike
|
|
254
|
-
def strike=(v)
|
|
262
|
+
def strike=(v)
|
|
263
|
+
set_run_style :validate_boolean, :strike, v
|
|
264
|
+
end
|
|
255
265
|
|
|
256
266
|
# The inline outline property for the cell
|
|
257
267
|
# @return [Boolean]
|
|
258
268
|
attr_reader :outline
|
|
259
269
|
|
|
260
270
|
# @see outline
|
|
261
|
-
def outline=(v)
|
|
271
|
+
def outline=(v)
|
|
272
|
+
set_run_style :validate_boolean, :outline, v
|
|
273
|
+
end
|
|
262
274
|
|
|
263
275
|
# The inline shadow property for the cell
|
|
264
276
|
# @return [Boolean]
|
|
265
277
|
attr_reader :shadow
|
|
266
278
|
|
|
267
279
|
# @see shadow
|
|
268
|
-
def shadow=(v)
|
|
280
|
+
def shadow=(v)
|
|
281
|
+
set_run_style :validate_boolean, :shadow, v
|
|
282
|
+
end
|
|
269
283
|
|
|
270
284
|
# The inline condense property for the cell
|
|
271
285
|
# @return [Boolean]
|
|
272
286
|
attr_reader :condense
|
|
273
287
|
|
|
274
288
|
# @see condense
|
|
275
|
-
def condense=(v)
|
|
289
|
+
def condense=(v)
|
|
290
|
+
set_run_style :validate_boolean, :condense, v
|
|
291
|
+
end
|
|
276
292
|
|
|
277
293
|
# The inline extend property for the cell
|
|
278
294
|
# @return [Boolean]
|
|
279
295
|
attr_reader :extend
|
|
280
296
|
|
|
281
297
|
# @see extend
|
|
282
|
-
def extend=(v)
|
|
298
|
+
def extend=(v)
|
|
299
|
+
set_run_style :validate_boolean, :extend, v
|
|
300
|
+
end
|
|
283
301
|
|
|
284
302
|
# The inline underline property for the cell.
|
|
285
303
|
# It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting
|
|
@@ -307,7 +325,9 @@ module Axlsx
|
|
|
307
325
|
attr_reader :sz
|
|
308
326
|
|
|
309
327
|
# @see sz
|
|
310
|
-
def sz=(v)
|
|
328
|
+
def sz=(v)
|
|
329
|
+
set_run_style :validate_unsigned_int, :sz, v
|
|
330
|
+
end
|
|
311
331
|
|
|
312
332
|
# The inline vertical alignment property for the cell
|
|
313
333
|
# this must be one of [:baseline, :subscript, :superscript]
|
|
@@ -529,14 +549,14 @@ module Axlsx
|
|
|
529
549
|
|
|
530
550
|
case type
|
|
531
551
|
when :date
|
|
532
|
-
self.style = STYLE_DATE if style
|
|
552
|
+
self.style = STYLE_DATE if style == 0
|
|
533
553
|
if !v.is_a?(Date) && v.respond_to?(:to_date)
|
|
534
554
|
v.to_date
|
|
535
555
|
else
|
|
536
556
|
v
|
|
537
557
|
end
|
|
538
558
|
when :time
|
|
539
|
-
self.style = STYLE_DATE if style
|
|
559
|
+
self.style = STYLE_DATE if style == 0
|
|
540
560
|
if !v.is_a?(Time) && v.respond_to?(:to_time)
|
|
541
561
|
v.to_time
|
|
542
562
|
else
|
|
@@ -7,7 +7,7 @@ module Axlsx
|
|
|
7
7
|
# Calls the proper serialization method based on type.
|
|
8
8
|
# @param [Integer] row_index The index of the cell's row
|
|
9
9
|
# @param [Integer] column_index The index of the cell's column
|
|
10
|
-
# @param [String] str The string to
|
|
10
|
+
# @param [String] str The string to append serialization to.
|
|
11
11
|
# @return [String]
|
|
12
12
|
def to_xml_string(row_index, column_index, cell, str = +'')
|
|
13
13
|
str << '<c r="'
|
|
@@ -40,10 +40,16 @@ module Axlsx
|
|
|
40
40
|
attr_reader :val
|
|
41
41
|
|
|
42
42
|
# @see type
|
|
43
|
-
def type=(v)
|
|
43
|
+
def type=(v)
|
|
44
|
+
Axlsx.validate_conditional_formatting_value_object_type(v)
|
|
45
|
+
@type = v
|
|
46
|
+
end
|
|
44
47
|
|
|
45
48
|
# @see gte
|
|
46
|
-
def gte=(v)
|
|
49
|
+
def gte=(v)
|
|
50
|
+
Axlsx.validate_boolean(v)
|
|
51
|
+
@gte = v
|
|
52
|
+
end
|
|
47
53
|
|
|
48
54
|
# @see val
|
|
49
55
|
def val=(v)
|
|
@@ -110,7 +110,7 @@ module Axlsx
|
|
|
110
110
|
def width=(v)
|
|
111
111
|
# Removing this validation make a 10% difference in performance
|
|
112
112
|
# as it is called EVERY TIME A CELL IS ADDED - the proper solution
|
|
113
|
-
# is to only set this if a calculated value is
|
|
113
|
+
# is to only set this if a calculated value is greater than the
|
|
114
114
|
# current @width value.
|
|
115
115
|
# TODO!!!
|
|
116
116
|
# Axlsx.validate_unsigned_numeric(v) unless v == nil
|
|
@@ -121,17 +121,30 @@ module Axlsx
|
|
|
121
121
|
# updates the width for this col based on the cells autowidth and
|
|
122
122
|
# an optionally specified fixed width
|
|
123
123
|
# @param [Cell] cell The cell to use in updating this col's width
|
|
124
|
-
# @param [
|
|
125
|
-
#
|
|
124
|
+
# @param [Numeric, :auto, :ignore, nil] fixed_width Decides how the width
|
|
125
|
+
# of the cell should be updated. If this is specified as as Numeric the
|
|
126
|
+
# width is set to this value and the cell's attributes are ignored. If set
|
|
127
|
+
# to `nil` or `:auto` and `use_autowidth` is true, it uses the autowidth of
|
|
128
|
+
# the cell. If set to `:ignore`, the cell's width is not changed. In any
|
|
129
|
+
# case the col's width is set to the new value only if the current width is
|
|
130
|
+
# smaller than the new one, so that the largest width of all cells in this
|
|
131
|
+
# column is used.
|
|
126
132
|
# @param [Boolean] use_autowidth If this is false, the cell's
|
|
127
133
|
# autowidth value will be ignored.
|
|
128
134
|
def update_width(cell, fixed_width = nil, use_autowidth = true)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
cell_width =
|
|
136
|
+
case fixed_width
|
|
137
|
+
when Numeric
|
|
138
|
+
fixed_width
|
|
139
|
+
when nil, :auto
|
|
140
|
+
cell.autowidth if use_autowidth
|
|
141
|
+
when :ignore
|
|
142
|
+
nil
|
|
143
|
+
else
|
|
144
|
+
raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
self.width = cell_width unless (width || 0) > (cell_width || 0)
|
|
135
148
|
end
|
|
136
149
|
|
|
137
150
|
# Serialize this columns data to an xml string
|
|
@@ -11,8 +11,8 @@ module Axlsx
|
|
|
11
11
|
# @param [Hash] options
|
|
12
12
|
# @option [String] author the author of the comment
|
|
13
13
|
# @option [String] text The text for the comment
|
|
14
|
-
# @option [String] ref The
|
|
15
|
-
# @option [Boolean] visible This controls the
|
|
14
|
+
# @option [String] ref The reference (e.g. 'A3' where this comment will be anchored.
|
|
15
|
+
# @option [Boolean] visible This controls the visibility of the associated vml_shape.
|
|
16
16
|
def initialize(comments, options = {})
|
|
17
17
|
raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
|
|
18
18
|
|
|
@@ -37,7 +37,7 @@ module Axlsx
|
|
|
37
37
|
# @note the author, text and ref options are required
|
|
38
38
|
# @option options [String] author The name of the author for this comment
|
|
39
39
|
# @option options [String] text The text for this comment
|
|
40
|
-
# @option options [
|
|
40
|
+
# @option options [String|Cell] ref The cell that this comment is attached to.
|
|
41
41
|
def add_comment(options = {})
|
|
42
42
|
raise ArgumentError, "Comment require an author" unless options[:author]
|
|
43
43
|
raise ArgumentError, "Comment requires text" unless options[:text]
|
|
@@ -61,9 +61,15 @@ module Axlsx
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
# @see rules
|
|
64
|
-
def rules=(v)
|
|
64
|
+
def rules=(v)
|
|
65
|
+
@rules = v
|
|
66
|
+
end
|
|
67
|
+
|
|
65
68
|
# @see sqref
|
|
66
|
-
def sqref=(v)
|
|
69
|
+
def sqref=(v)
|
|
70
|
+
Axlsx.validate_string(v)
|
|
71
|
+
@sqref = v
|
|
72
|
+
end
|
|
67
73
|
|
|
68
74
|
# Serializes the conditional formatting element
|
|
69
75
|
# @example Conditional Formatting XML looks like:
|
|
@@ -77,7 +83,7 @@ module Axlsx
|
|
|
77
83
|
def to_xml_string(str = +'')
|
|
78
84
|
str << '<conditionalFormatting sqref="' << sqref << '">'
|
|
79
85
|
rules.each_with_index do |rule, index|
|
|
80
|
-
str << ' ' unless index
|
|
86
|
+
str << ' ' unless index == 0
|
|
81
87
|
rule.to_xml_string(str)
|
|
82
88
|
end
|
|
83
89
|
str << '</conditionalFormatting>'
|
|
@@ -24,7 +24,7 @@ module Axlsx
|
|
|
24
24
|
# @option options [Integer] rank If a top/bottom N rule, the value of N
|
|
25
25
|
# @option options [Integer] stdDev The number of standard deviations above or below the average to match
|
|
26
26
|
# @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
|
|
27
|
-
# @option options [Symbol] timePeriod The time period in a date
|
|
27
|
+
# @option options [Symbol] timePeriod The time period in a date occurring... rule
|
|
28
28
|
# @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.
|
|
29
29
|
def initialize(options = {})
|
|
30
30
|
@color_scale = @data_bar = @icon_set = @formula = nil
|
|
@@ -155,33 +155,88 @@ module Axlsx
|
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
# @see type
|
|
158
|
-
def type=(v)
|
|
158
|
+
def type=(v)
|
|
159
|
+
Axlsx.validate_conditional_formatting_type(v)
|
|
160
|
+
@type = v
|
|
161
|
+
end
|
|
162
|
+
|
|
159
163
|
# @see aboveAverage
|
|
160
|
-
def aboveAverage=(v)
|
|
164
|
+
def aboveAverage=(v)
|
|
165
|
+
Axlsx.validate_boolean(v)
|
|
166
|
+
@aboveAverage = v
|
|
167
|
+
end
|
|
168
|
+
|
|
161
169
|
# @see bottom
|
|
162
|
-
def bottom=(v)
|
|
170
|
+
def bottom=(v)
|
|
171
|
+
Axlsx.validate_boolean(v)
|
|
172
|
+
@bottom = v
|
|
173
|
+
end
|
|
174
|
+
|
|
163
175
|
# @see dxfId
|
|
164
|
-
def dxfId=(v)
|
|
176
|
+
def dxfId=(v)
|
|
177
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
178
|
+
@dxfId = v
|
|
179
|
+
end
|
|
180
|
+
|
|
165
181
|
# @see equalAverage
|
|
166
|
-
def equalAverage=(v)
|
|
182
|
+
def equalAverage=(v)
|
|
183
|
+
Axlsx.validate_boolean(v)
|
|
184
|
+
@equalAverage = v
|
|
185
|
+
end
|
|
186
|
+
|
|
167
187
|
# @see priority
|
|
168
|
-
def priority=(v)
|
|
188
|
+
def priority=(v)
|
|
189
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
190
|
+
@priority = v
|
|
191
|
+
end
|
|
192
|
+
|
|
169
193
|
# @see operator
|
|
170
|
-
def operator=(v)
|
|
194
|
+
def operator=(v)
|
|
195
|
+
Axlsx.validate_conditional_formatting_operator(v)
|
|
196
|
+
@operator = v
|
|
197
|
+
end
|
|
198
|
+
|
|
171
199
|
# @see text
|
|
172
|
-
def text=(v)
|
|
200
|
+
def text=(v)
|
|
201
|
+
Axlsx.validate_string(v)
|
|
202
|
+
@text = v
|
|
203
|
+
end
|
|
204
|
+
|
|
173
205
|
# @see percent
|
|
174
|
-
def percent=(v)
|
|
206
|
+
def percent=(v)
|
|
207
|
+
Axlsx.validate_boolean(v)
|
|
208
|
+
@percent = v
|
|
209
|
+
end
|
|
210
|
+
|
|
175
211
|
# @see rank
|
|
176
|
-
def rank=(v)
|
|
212
|
+
def rank=(v)
|
|
213
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
214
|
+
@rank = v
|
|
215
|
+
end
|
|
216
|
+
|
|
177
217
|
# @see stdDev
|
|
178
|
-
def stdDev=(v)
|
|
218
|
+
def stdDev=(v)
|
|
219
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
220
|
+
@stdDev = v
|
|
221
|
+
end
|
|
222
|
+
|
|
179
223
|
# @see stopIfTrue
|
|
180
|
-
def stopIfTrue=(v)
|
|
224
|
+
def stopIfTrue=(v)
|
|
225
|
+
Axlsx.validate_boolean(v)
|
|
226
|
+
@stopIfTrue = v
|
|
227
|
+
end
|
|
228
|
+
|
|
181
229
|
# @see timePeriod
|
|
182
|
-
def timePeriod=(v)
|
|
230
|
+
def timePeriod=(v)
|
|
231
|
+
Axlsx.validate_time_period_type(v)
|
|
232
|
+
@timePeriod = v
|
|
233
|
+
end
|
|
234
|
+
|
|
183
235
|
# @see formula
|
|
184
|
-
def formula=(v)
|
|
236
|
+
def formula=(v)
|
|
237
|
+
[*v].each { |x| Axlsx.validate_string(x) }
|
|
238
|
+
@formula = [*v].map { |form| ::CGI.escapeHTML(form) }
|
|
239
|
+
end
|
|
185
240
|
|
|
186
241
|
# @see color_scale
|
|
187
242
|
def color_scale=(v)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Axlsx
|
|
4
|
-
# A simple, self serializing class for storing conditional
|
|
4
|
+
# A simple, self serializing class for storing conditional formatting
|
|
5
5
|
class ConditionalFormattings < SimpleTypedList
|
|
6
6
|
# creates a new Tables object
|
|
7
7
|
def initialize(worksheet)
|
|
8
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
9
9
|
|
|
10
|
-
super
|
|
10
|
+
super(ConditionalFormatting)
|
|
11
11
|
@worksheet = worksheet
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ module Axlsx
|
|
|
15
15
|
# @return [Worksheet]
|
|
16
16
|
attr_reader :worksheet
|
|
17
17
|
|
|
18
|
-
# serialize the conditional
|
|
18
|
+
# serialize the conditional formatting
|
|
19
19
|
def to_xml_string(str = +'')
|
|
20
20
|
return if empty?
|
|
21
21
|
|
|
@@ -178,31 +178,58 @@ module Axlsx
|
|
|
178
178
|
attr_reader :type
|
|
179
179
|
|
|
180
180
|
# @see formula1
|
|
181
|
-
def formula1=(v)
|
|
181
|
+
def formula1=(v)
|
|
182
|
+
Axlsx.validate_string(v)
|
|
183
|
+
@formula1 = v
|
|
184
|
+
end
|
|
182
185
|
|
|
183
186
|
# @see formula2
|
|
184
|
-
def formula2=(v)
|
|
187
|
+
def formula2=(v)
|
|
188
|
+
Axlsx.validate_string(v)
|
|
189
|
+
@formula2 = v
|
|
190
|
+
end
|
|
185
191
|
|
|
186
192
|
# @see allowBlank
|
|
187
|
-
def allowBlank=(v)
|
|
193
|
+
def allowBlank=(v)
|
|
194
|
+
Axlsx.validate_boolean(v)
|
|
195
|
+
@allowBlank = v
|
|
196
|
+
end
|
|
188
197
|
|
|
189
198
|
# @see error
|
|
190
|
-
def error=(v)
|
|
199
|
+
def error=(v)
|
|
200
|
+
Axlsx.validate_string(v)
|
|
201
|
+
@error = v
|
|
202
|
+
end
|
|
191
203
|
|
|
192
204
|
# @see errorStyle
|
|
193
|
-
def errorStyle=(v)
|
|
205
|
+
def errorStyle=(v)
|
|
206
|
+
Axlsx.validate_data_validation_error_style(v)
|
|
207
|
+
@errorStyle = v
|
|
208
|
+
end
|
|
194
209
|
|
|
195
210
|
# @see errorTitle
|
|
196
|
-
def errorTitle=(v)
|
|
211
|
+
def errorTitle=(v)
|
|
212
|
+
Axlsx.validate_string(v)
|
|
213
|
+
@errorTitle = v
|
|
214
|
+
end
|
|
197
215
|
|
|
198
216
|
# @see operator
|
|
199
|
-
def operator=(v)
|
|
217
|
+
def operator=(v)
|
|
218
|
+
Axlsx.validate_data_validation_operator(v)
|
|
219
|
+
@operator = v
|
|
220
|
+
end
|
|
200
221
|
|
|
201
222
|
# @see prompt
|
|
202
|
-
def prompt=(v)
|
|
223
|
+
def prompt=(v)
|
|
224
|
+
Axlsx.validate_string(v)
|
|
225
|
+
@prompt = v
|
|
226
|
+
end
|
|
203
227
|
|
|
204
228
|
# @see promptTitle
|
|
205
|
-
def promptTitle=(v)
|
|
229
|
+
def promptTitle=(v)
|
|
230
|
+
Axlsx.validate_string(v)
|
|
231
|
+
@promptTitle = v
|
|
232
|
+
end
|
|
206
233
|
|
|
207
234
|
# @see showDropDown
|
|
208
235
|
def showDropDown=(v)
|
|
@@ -219,16 +246,28 @@ module Axlsx
|
|
|
219
246
|
end
|
|
220
247
|
|
|
221
248
|
# @see showErrorMessage
|
|
222
|
-
def showErrorMessage=(v)
|
|
249
|
+
def showErrorMessage=(v)
|
|
250
|
+
Axlsx.validate_boolean(v)
|
|
251
|
+
@showErrorMessage = v
|
|
252
|
+
end
|
|
223
253
|
|
|
224
254
|
# @see showInputMessage
|
|
225
|
-
def showInputMessage=(v)
|
|
255
|
+
def showInputMessage=(v)
|
|
256
|
+
Axlsx.validate_boolean(v)
|
|
257
|
+
@showInputMessage = v
|
|
258
|
+
end
|
|
226
259
|
|
|
227
260
|
# @see sqref
|
|
228
|
-
def sqref=(v)
|
|
261
|
+
def sqref=(v)
|
|
262
|
+
Axlsx.validate_string(v)
|
|
263
|
+
@sqref = v
|
|
264
|
+
end
|
|
229
265
|
|
|
230
266
|
# @see type
|
|
231
|
-
def type=(v)
|
|
267
|
+
def type=(v)
|
|
268
|
+
Axlsx.validate_data_validation_type(v)
|
|
269
|
+
@type = v
|
|
270
|
+
end
|
|
232
271
|
|
|
233
272
|
# Serializes the data validation
|
|
234
273
|
# @param [String] str
|
|
@@ -239,7 +278,7 @@ module Axlsx
|
|
|
239
278
|
|
|
240
279
|
str << '<dataValidation '
|
|
241
280
|
h.each_with_index do |key_value, index|
|
|
242
|
-
str << ' ' unless index
|
|
281
|
+
str << ' ' unless index == 0
|
|
243
282
|
str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
|
|
244
283
|
end
|
|
245
284
|
str << '>'
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Axlsx
|
|
4
|
-
# A simple, self serializing class for storing conditional
|
|
4
|
+
# A simple, self serializing class for storing conditional formatting
|
|
5
5
|
class DataValidations < SimpleTypedList
|
|
6
6
|
# creates a new Tables object
|
|
7
7
|
def initialize(worksheet)
|
|
8
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
9
9
|
|
|
10
|
-
super
|
|
10
|
+
super(DataValidation)
|
|
11
11
|
@worksheet = worksheet
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ module Axlsx
|
|
|
15
15
|
# @return [Worksheet]
|
|
16
16
|
attr_reader :worksheet
|
|
17
17
|
|
|
18
|
-
# serialize the conditional
|
|
18
|
+
# serialize the conditional formatting
|
|
19
19
|
def to_xml_string(str = +'')
|
|
20
20
|
return if empty?
|
|
21
21
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
require "date"
|
|
4
4
|
|
|
5
5
|
module Axlsx
|
|
6
|
-
# The DateTimeConverter class converts both data and time types to their
|
|
6
|
+
# The DateTimeConverter class converts both data and time types to their appropriate Excel serializations
|
|
7
7
|
class DateTimeConverter
|
|
8
|
-
# The date_to_serial method converts Date objects to the
|
|
8
|
+
# The date_to_serial method converts Date objects to the equivalent Excel serialized forms
|
|
9
9
|
# @param [Date] date the date to be serialized
|
|
10
10
|
# @return [Numeric]
|
|
11
11
|
def self.date_to_serial(date)
|