caxlsx 3.3.0 → 4.5.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 +87 -11
- data/README.md +43 -16
- data/Rakefile +5 -11
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
- data/lib/axlsx/content_type/content_type.rb +8 -10
- data/lib/axlsx/content_type/default.rb +7 -6
- data/lib/axlsx/content_type/override.rb +6 -5
- data/lib/axlsx/doc_props/app.rb +96 -32
- data/lib/axlsx/doc_props/core.rb +9 -12
- data/lib/axlsx/drawing/area_chart.rb +16 -17
- data/lib/axlsx/drawing/area_series.rb +23 -18
- data/lib/axlsx/drawing/ax_data_source.rb +4 -7
- data/lib/axlsx/drawing/axes.rb +11 -10
- data/lib/axlsx/drawing/axis.rb +83 -36
- data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
- data/lib/axlsx/drawing/bar_chart.rb +29 -20
- data/lib/axlsx/drawing/bar_series.rb +23 -18
- data/lib/axlsx/drawing/bubble_chart.rb +9 -10
- data/lib/axlsx/drawing/bubble_series.rb +11 -12
- data/lib/axlsx/drawing/cat_axis.rb +38 -28
- data/lib/axlsx/drawing/chart.rb +52 -30
- data/lib/axlsx/drawing/d_lbls.rb +36 -32
- data/lib/axlsx/drawing/drawing.rb +61 -62
- data/lib/axlsx/drawing/graphic_frame.rb +6 -7
- data/lib/axlsx/drawing/hyperlink.rb +22 -14
- data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
- data/lib/axlsx/drawing/line_chart.rb +16 -17
- data/lib/axlsx/drawing/line_series.rb +23 -18
- data/lib/axlsx/drawing/marker.rb +29 -16
- data/lib/axlsx/drawing/num_data.rb +13 -16
- data/lib/axlsx/drawing/num_data_source.rb +11 -13
- data/lib/axlsx/drawing/num_val.rb +10 -11
- data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
- data/lib/axlsx/drawing/pic.rb +68 -24
- data/lib/axlsx/drawing/picture_locking.rb +6 -7
- data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +26 -17
- data/lib/axlsx/drawing/scaling.rb +26 -13
- data/lib/axlsx/drawing/scatter_chart.rb +10 -11
- data/lib/axlsx/drawing/scatter_series.rb +17 -18
- data/lib/axlsx/drawing/ser_axis.rb +22 -19
- data/lib/axlsx/drawing/series.rb +14 -8
- data/lib/axlsx/drawing/series_title.rb +6 -6
- data/lib/axlsx/drawing/str_data.rb +10 -13
- data/lib/axlsx/drawing/str_val.rb +8 -9
- data/lib/axlsx/drawing/title.rb +23 -27
- data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
- data/lib/axlsx/drawing/val_axis.rb +7 -8
- data/lib/axlsx/drawing/view_3D.rb +38 -30
- data/lib/axlsx/drawing/vml_drawing.rb +19 -20
- data/lib/axlsx/drawing/vml_shape.rb +25 -26
- data/lib/axlsx/package.rb +134 -99
- data/lib/axlsx/rels/relationship.rb +42 -30
- data/lib/axlsx/rels/relationships.rb +9 -10
- data/lib/axlsx/stylesheet/border.rb +16 -8
- data/lib/axlsx/stylesheet/border_pr.rb +24 -12
- data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
- data/lib/axlsx/stylesheet/cell_style.rb +36 -15
- data/lib/axlsx/stylesheet/color.rb +23 -14
- data/lib/axlsx/stylesheet/dxf.rb +36 -15
- data/lib/axlsx/stylesheet/fill.rb +7 -6
- data/lib/axlsx/stylesheet/font.rb +71 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
- data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
- data/lib/axlsx/stylesheet/styles.rb +167 -118
- data/lib/axlsx/stylesheet/table_style.rb +20 -10
- data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
- data/lib/axlsx/stylesheet/table_styles.rb +16 -11
- data/lib/axlsx/stylesheet/theme.rb +163 -0
- data/lib/axlsx/stylesheet/xf.rb +78 -25
- data/lib/axlsx/util/accessors.rb +13 -11
- data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
- data/lib/axlsx/util/constants.rb +133 -110
- data/lib/axlsx/util/mime_type_utils.rb +75 -5
- data/lib/axlsx/util/options_parser.rb +4 -3
- data/lib/axlsx/util/serialized_attributes.rb +47 -23
- data/lib/axlsx/util/simple_typed_list.rb +77 -64
- data/lib/axlsx/util/storage.rb +38 -41
- data/lib/axlsx/util/uri_utils.rb +70 -0
- data/lib/axlsx/util/validators.rb +111 -48
- data/lib/axlsx/util/zip_command.rb +10 -12
- data/lib/axlsx/version.rb +3 -2
- data/lib/axlsx/workbook/defined_name.rb +13 -9
- data/lib/axlsx/workbook/defined_names.rb +5 -4
- data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
- data/lib/axlsx/workbook/workbook.rb +152 -120
- data/lib/axlsx/workbook/workbook_view.rb +9 -12
- data/lib/axlsx/workbook/workbook_views.rb +5 -5
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
- data/lib/axlsx/workbook/worksheet/break.rb +4 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
- data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
- data/lib/axlsx/workbook/worksheet/col.rb +32 -19
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
- data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
- data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
- data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
- data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
- data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
- data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
- data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
- data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
- data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
- data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
- data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
- data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
- data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
- data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
- data/lib/axlsx/workbook/worksheet/row.rb +34 -23
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
- data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
- data/lib/axlsx/workbook/worksheet/table.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
- data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
- data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
- data/lib/axlsx.rb +120 -60
- data/lib/caxlsx.rb +3 -2
- metadata +42 -75
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# Conditional Format Value Object
|
|
3
5
|
# Describes the values of the interpolation points in a gradient scale. This object is used by ColorScale, DataBar and IconSet classes
|
|
@@ -7,7 +9,6 @@ module Axlsx
|
|
|
7
9
|
# @see ConditionalFormattingRule#initialize
|
|
8
10
|
#
|
|
9
11
|
class Cfvo
|
|
10
|
-
|
|
11
12
|
include Axlsx::OptionsParser
|
|
12
13
|
include Axlsx::SerializedAttributes
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ module Axlsx
|
|
|
15
16
|
# @option options [Symbol] type The type of conditional formatting value object
|
|
16
17
|
# @option options [Boolean] gte threshold value usage indicator
|
|
17
18
|
# @option options [String] val The value of the conditional formatting object
|
|
18
|
-
def initialize(options={})
|
|
19
|
+
def initialize(options = {})
|
|
19
20
|
@gte = true
|
|
20
21
|
parse_options options
|
|
21
22
|
end
|
|
@@ -39,21 +40,28 @@ module Axlsx
|
|
|
39
40
|
attr_reader :val
|
|
40
41
|
|
|
41
42
|
# @see type
|
|
42
|
-
def type=(v)
|
|
43
|
+
def type=(v)
|
|
44
|
+
Axlsx.validate_conditional_formatting_value_object_type(v)
|
|
45
|
+
@type = v
|
|
46
|
+
end
|
|
43
47
|
|
|
44
48
|
# @see gte
|
|
45
|
-
def gte=(v)
|
|
49
|
+
def gte=(v)
|
|
50
|
+
Axlsx.validate_boolean(v)
|
|
51
|
+
@gte = v
|
|
52
|
+
end
|
|
46
53
|
|
|
47
54
|
# @see val
|
|
48
55
|
def val=(v)
|
|
49
56
|
raise ArgumentError, "#{v.inspect} must respond to to_s" unless v.respond_to?(:to_s)
|
|
57
|
+
|
|
50
58
|
@val = v.to_s
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
# serialize the Csvo object
|
|
54
62
|
# @param [String] str
|
|
55
63
|
# @return [String]
|
|
56
|
-
def to_xml_string(str = '')
|
|
64
|
+
def to_xml_string(str = +'')
|
|
57
65
|
serialized_tag('cfvo', str)
|
|
58
66
|
end
|
|
59
67
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
3
|
+
module Axlsx
|
|
4
|
+
# A collection of Cfvo objects that initializes with the required
|
|
5
|
+
# first two items
|
|
5
6
|
class Cfvos < SimpleTypedList
|
|
6
|
-
|
|
7
7
|
def initialize
|
|
8
8
|
super(Cfvo)
|
|
9
9
|
end
|
|
@@ -11,7 +11,7 @@ module Axlsx
|
|
|
11
11
|
# Serialize the Cfvo object
|
|
12
12
|
# @param [String] str
|
|
13
13
|
# @return [String]
|
|
14
|
-
def to_xml_string(str='')
|
|
14
|
+
def to_xml_string(str = +'')
|
|
15
15
|
each { |cfvo| cfvo.to_xml_string(str) }
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#
|
|
2
|
-
module Axlsx
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
module Axlsx
|
|
4
4
|
# The Col class defines column attributes for columns in sheets.
|
|
5
5
|
class Col
|
|
6
|
-
|
|
7
6
|
# Maximum column width limit in MS Excel is 255 characters
|
|
8
7
|
# https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
|
|
9
8
|
MAX_WIDTH = 255
|
|
10
9
|
|
|
11
10
|
include Axlsx::OptionsParser
|
|
12
11
|
include Axlsx::SerializedAttributes
|
|
12
|
+
|
|
13
13
|
# Create a new Col objects
|
|
14
14
|
# @param min First column affected by this 'column info' record.
|
|
15
15
|
# @param max Last column affected by this 'column info' record.
|
|
@@ -19,7 +19,7 @@ module Axlsx
|
|
|
19
19
|
# @option options [Boolean] phonetic see Col#phonetic
|
|
20
20
|
# @option options [Integer] style see Col#style
|
|
21
21
|
# @option options [Numeric] width see Col#width
|
|
22
|
-
def initialize(min, max, options={})
|
|
22
|
+
def initialize(min, max, options = {})
|
|
23
23
|
Axlsx.validate_unsigned_int(max)
|
|
24
24
|
Axlsx.validate_unsigned_int(min)
|
|
25
25
|
@min = min
|
|
@@ -89,7 +89,8 @@ module Axlsx
|
|
|
89
89
|
# @see Col#outline
|
|
90
90
|
def outline_level=(v)
|
|
91
91
|
Axlsx.validate_unsigned_numeric(v)
|
|
92
|
-
raise ArgumentError, 'outlineLevel must be between 0 and 7' unless
|
|
92
|
+
raise ArgumentError, 'outlineLevel must be between 0 and 7' unless v >= 0 && v <= 7
|
|
93
|
+
|
|
93
94
|
@outline_level = v
|
|
94
95
|
end
|
|
95
96
|
alias :outlineLevel= :outline_level=
|
|
@@ -106,40 +107,52 @@ module Axlsx
|
|
|
106
107
|
@style = v
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
# @see Col#width
|
|
110
111
|
def width=(v)
|
|
111
112
|
# Removing this validation make a 10% difference in performance
|
|
112
113
|
# as it is called EVERY TIME A CELL IS ADDED - the proper solution
|
|
113
|
-
# is to only set this if a calculated value is
|
|
114
|
+
# is to only set this if a calculated value is greater than the
|
|
114
115
|
# current @width value.
|
|
115
116
|
# TODO!!!
|
|
116
|
-
#Axlsx.validate_unsigned_numeric(v) unless v == nil
|
|
117
|
-
@custom_width = @best_fit = v
|
|
117
|
+
# Axlsx.validate_unsigned_numeric(v) unless v == nil
|
|
118
|
+
@custom_width = @best_fit = !v.nil?
|
|
118
119
|
@width = v.nil? ? v : [v, MAX_WIDTH].min
|
|
119
120
|
end
|
|
120
121
|
|
|
121
122
|
# updates the width for this col based on the cells autowidth and
|
|
122
123
|
# an optionally specified fixed width
|
|
123
124
|
# @param [Cell] cell The cell to use in updating this col's width
|
|
124
|
-
# @param [
|
|
125
|
-
#
|
|
125
|
+
# @param [Numeric, :auto, :ignore, nil] fixed_width Decides how the width
|
|
126
|
+
# of the cell should be updated. If this is specified as as Numeric the
|
|
127
|
+
# width is set to this value and the cell's attributes are ignored. If set
|
|
128
|
+
# to `nil` or `:auto` and `use_autowidth` is true, it uses the autowidth of
|
|
129
|
+
# the cell. If set to `:ignore`, the cell's width is not changed. In any
|
|
130
|
+
# case the col's width is set to the new value only if the current width is
|
|
131
|
+
# smaller than the new one, so that the largest width of all cells in this
|
|
132
|
+
# column is used.
|
|
126
133
|
# @param [Boolean] use_autowidth If this is false, the cell's
|
|
127
134
|
# autowidth value will be ignored.
|
|
128
135
|
def update_width(cell, fixed_width = nil, use_autowidth = true)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
cell_width =
|
|
137
|
+
case fixed_width
|
|
138
|
+
when Numeric
|
|
139
|
+
fixed_width
|
|
140
|
+
when nil, :auto
|
|
141
|
+
cell.autowidth if use_autowidth
|
|
142
|
+
when :ignore
|
|
143
|
+
nil
|
|
144
|
+
else
|
|
145
|
+
raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
self.width = cell_width unless (width || 0) > (cell_width || 0)
|
|
135
149
|
end
|
|
136
150
|
|
|
137
151
|
# Serialize this columns data to an xml string
|
|
138
152
|
# @param [String] str
|
|
139
153
|
# @return [String]
|
|
140
|
-
def to_xml_string(str = '')
|
|
154
|
+
def to_xml_string(str = +'')
|
|
141
155
|
serialized_tag('col', str)
|
|
142
156
|
end
|
|
143
|
-
|
|
144
157
|
end
|
|
145
158
|
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# A collection of Brake objects.
|
|
4
|
-
# Please do not use this class directly. Instead use
|
|
5
|
+
# Please do not use this class directly. Instead use
|
|
5
6
|
# Worksheet#add_break
|
|
6
7
|
class ColBreaks < SimpleTypedList
|
|
7
|
-
|
|
8
8
|
# Instantiates a new list restricted to Break types
|
|
9
9
|
def initialize
|
|
10
|
-
super
|
|
10
|
+
super(Break)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# A column break specific helper for adding a break.
|
|
14
14
|
# @param [Hash] options A list of options to pass into the Break object
|
|
15
|
-
# The max and man options are fixed, however any other valid option for
|
|
15
|
+
# The max and man options are fixed, however any other valid option for
|
|
16
16
|
# Break will be passed to the created break object.
|
|
17
17
|
# @see Break
|
|
18
18
|
def add_break(options)
|
|
19
|
-
self << Break.new(options.merge(:
|
|
19
|
+
self << Break.new(options.merge(max: 1048575, man: true))
|
|
20
20
|
last
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -25,9 +25,10 @@ module Axlsx
|
|
|
25
25
|
# <colBreaks count="1" manualBreakCount="1">
|
|
26
26
|
# <brk id="3" max="1048575" man="1"/>
|
|
27
27
|
# </colBreaks>
|
|
28
|
-
def to_xml_string(str='')
|
|
28
|
+
def to_xml_string(str = +'')
|
|
29
29
|
return if empty?
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
str << '<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
|
|
31
32
|
each { |brk| brk.to_xml_string(str) }
|
|
32
33
|
str << '</colBreaks>'
|
|
33
34
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# Conditional Format Rule color scale object
|
|
3
5
|
# Describes a gradated color scale in this conditional formatting rule.
|
|
@@ -6,14 +8,12 @@ module Axlsx
|
|
|
6
8
|
# @see Worksheet#add_conditional_formatting
|
|
7
9
|
# @see ConditionalFormattingRule#initialize
|
|
8
10
|
class ColorScale
|
|
9
|
-
|
|
10
11
|
class << self
|
|
11
|
-
|
|
12
12
|
# These are the default conditional formatting value objects
|
|
13
13
|
# that define a two tone color gradient.
|
|
14
14
|
def default_cfvos
|
|
15
|
-
[{:
|
|
16
|
-
{:
|
|
15
|
+
[{ type: :min, val: 0, color: 'FFFF7128' },
|
|
16
|
+
{ type: :max, val: 0, color: 'FFFFEF9C' }]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# A builder for two tone color gradient
|
|
@@ -22,18 +22,18 @@ module Axlsx
|
|
|
22
22
|
# color_scale = Axlsx::ColorScale.two_tone
|
|
23
23
|
# @see examples/example.rb conditional formatting examples.
|
|
24
24
|
def two_tone
|
|
25
|
-
|
|
25
|
+
new
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# A builder for three tone color gradient
|
|
29
29
|
# @example
|
|
30
30
|
# #this creates a three tone color scale
|
|
31
|
-
# color_scale = Axlsx::ColorScale.three_tone
|
|
31
|
+
# color_scale = Axlsx::ColorScale.three_tone
|
|
32
32
|
# @see examples/example.rb conditional formatting examples.
|
|
33
33
|
def three_tone
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
new({ type: :min, val: 0, color: 'FFF8696B' },
|
|
35
|
+
{ type: :percent, val: '50', color: 'FFFFEB84' },
|
|
36
|
+
{ type: :max, val: 0, color: 'FF63BE7B' })
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
# A simple typed list of cfvos
|
|
@@ -67,17 +67,16 @@ module Axlsx
|
|
|
67
67
|
# @option [Symbol] type The type of cfvo you to add
|
|
68
68
|
# @option [Any] val The value of the cfvo to add
|
|
69
69
|
# @option [String] The rgb color for the cfvo
|
|
70
|
-
def add(options={})
|
|
71
|
-
value_objects << Cfvo.new(:
|
|
72
|
-
colors << Color.new(:
|
|
73
|
-
{:
|
|
70
|
+
def add(options = {})
|
|
71
|
+
value_objects << Cfvo.new(type: options[:type] || :min, val: options[:val] || 0)
|
|
72
|
+
colors << Color.new(rgb: options[:color] || "FF000000")
|
|
73
|
+
{ cfvo: value_objects.last, color: colors.last }
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
|
|
77
76
|
# removes the cfvo and color pair at the index specified.
|
|
78
77
|
# @param [Integer] index The index of the cfvo and color object to delete
|
|
79
78
|
# @note you cannot remove the first two cfvo and color pairs
|
|
80
|
-
def delete_at(index=2)
|
|
79
|
+
def delete_at(index = 2)
|
|
81
80
|
value_objects.delete_at index
|
|
82
81
|
colors.delete_at index
|
|
83
82
|
end
|
|
@@ -85,7 +84,7 @@ module Axlsx
|
|
|
85
84
|
# Serialize this color_scale object data to an xml string
|
|
86
85
|
# @param [String] str
|
|
87
86
|
# @return [String]
|
|
88
|
-
def to_xml_string(str = '')
|
|
87
|
+
def to_xml_string(str = +'')
|
|
89
88
|
str << '<colorScale>'
|
|
90
89
|
value_objects.to_xml_string(str)
|
|
91
90
|
colors.each { |color| color.to_xml_string(str) }
|
|
@@ -93,6 +92,7 @@ module Axlsx
|
|
|
93
92
|
end
|
|
94
93
|
|
|
95
94
|
private
|
|
95
|
+
|
|
96
96
|
# There has got to be cleaner way of merging these arrays.
|
|
97
97
|
def initialize_default_cfvos(user_cfvos)
|
|
98
98
|
defaults = self.class.default_cfvos
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# The cols class manages the col object used to manage column widths.
|
|
4
5
|
# This is where the magic happens with autowidth
|
|
5
6
|
class Cols < SimpleTypedList
|
|
6
|
-
|
|
7
7
|
def initialize(worksheet)
|
|
8
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
super(Col)
|
|
10
11
|
@worksheet = worksheet
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
# Serialize the Cols object
|
|
14
15
|
# @param [String] str
|
|
15
16
|
# @return [String]
|
|
16
|
-
def to_xml_string(str = '')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
def to_xml_string(str = +'')
|
|
18
|
+
return if empty?
|
|
19
|
+
|
|
20
|
+
str << '<cols>'
|
|
21
|
+
each { |item| item.to_xml_string(str) }
|
|
22
|
+
str << '</cols>'
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# A comment is the text data for a comment
|
|
4
5
|
class Comment
|
|
5
|
-
|
|
6
6
|
include Axlsx::OptionsParser
|
|
7
7
|
include Axlsx::Accessors
|
|
8
8
|
|
|
@@ -11,10 +11,11 @@ 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
|
|
16
|
-
def initialize(comments, options={})
|
|
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
|
+
def initialize(comments, options = {})
|
|
17
17
|
raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
|
|
18
|
+
|
|
18
19
|
@visible = true
|
|
19
20
|
@comments = comments
|
|
20
21
|
parse_options options
|
|
@@ -60,17 +61,17 @@ module Axlsx
|
|
|
60
61
|
# serialize the object
|
|
61
62
|
# @param [String] str
|
|
62
63
|
# @return [String]
|
|
63
|
-
def to_xml_string(str =
|
|
64
|
+
def to_xml_string(str = +'')
|
|
64
65
|
author = @comments.authors[author_index]
|
|
65
|
-
str <<
|
|
66
|
+
str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
|
|
66
67
|
str << '<text>'
|
|
67
68
|
unless author.to_s == ""
|
|
68
69
|
str << '<r><rPr><b/><color indexed="81"/></rPr>'
|
|
69
|
-
str <<
|
|
70
|
+
str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
|
|
70
71
|
end
|
|
71
72
|
str << '<r>'
|
|
72
73
|
str << '<rPr><color indexed="81"/></rPr>'
|
|
73
|
-
str <<
|
|
74
|
+
str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
|
|
74
75
|
str << '</comment>'
|
|
75
76
|
end
|
|
76
77
|
|
|
@@ -79,12 +80,12 @@ module Axlsx
|
|
|
79
80
|
# initialize the vml shape based on this comment's ref/position in the worksheet.
|
|
80
81
|
# by default, all columns are 5 columns wide and 5 rows high
|
|
81
82
|
def initialize_vml_shape
|
|
82
|
-
pos = Axlsx
|
|
83
|
-
@vml_shape = VmlShape.new(:
|
|
83
|
+
pos = Axlsx.name_to_indices(ref)
|
|
84
|
+
@vml_shape = VmlShape.new(row: pos[1], column: pos[0], visible: @visible) do |vml|
|
|
84
85
|
vml.left_column = vml.column
|
|
85
|
-
vml.right_column = vml.column + 2
|
|
86
|
+
vml.right_column = vml.column + 2
|
|
86
87
|
vml.top_row = vml.row
|
|
87
|
-
|
|
88
|
+
vml.bottom_row = vml.row + 4
|
|
88
89
|
end
|
|
89
90
|
end
|
|
90
91
|
end
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
module Axlsx
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
module Axlsx
|
|
4
4
|
# Comments is a collection of Comment objects for a worksheet
|
|
5
5
|
class Comments < SimpleTypedList
|
|
6
|
-
|
|
7
6
|
# the vml_drawing that holds the shapes for comments
|
|
8
7
|
# @return [VmlDrawing]
|
|
9
8
|
attr_reader :vml_drawing
|
|
@@ -21,13 +20,14 @@ module Axlsx
|
|
|
21
20
|
# The part name for this object
|
|
22
21
|
# @return [String]
|
|
23
22
|
def pn
|
|
24
|
-
|
|
23
|
+
format(COMMENT_PN, index + 1)
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
# Creates a new Comments object
|
|
28
27
|
# @param [Worksheet] worksheet The sheet that these comments belong to.
|
|
29
28
|
def initialize(worksheet)
|
|
30
29
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
30
|
+
|
|
31
31
|
super(Comment)
|
|
32
32
|
@worksheet = worksheet
|
|
33
33
|
@vml_drawing = VmlDrawing.new(self)
|
|
@@ -37,11 +37,12 @@ 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 [
|
|
41
|
-
def add_comment(options={})
|
|
40
|
+
# @option options [String|Cell] ref The cell that this comment is attached to.
|
|
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]
|
|
44
44
|
raise ArgumentError, "Comment requires ref" unless options[:ref]
|
|
45
|
+
|
|
45
46
|
self << Comment.new(self, options)
|
|
46
47
|
yield last if block_given?
|
|
47
48
|
last
|
|
@@ -63,20 +64,17 @@ module Axlsx
|
|
|
63
64
|
# serialize the object
|
|
64
65
|
# @param [String] str
|
|
65
66
|
# @return [String]
|
|
66
|
-
def to_xml_string(str=
|
|
67
|
+
def to_xml_string(str = +'')
|
|
67
68
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
68
|
-
str <<
|
|
69
|
-
authors.each do
|
|
70
|
-
str <<
|
|
69
|
+
str << '<comments xmlns="' << XML_NS << '"><authors>'
|
|
70
|
+
authors.each do |author|
|
|
71
|
+
str << '<author>' << author.to_s << '</author>'
|
|
71
72
|
end
|
|
72
73
|
str << '</authors><commentList>'
|
|
73
74
|
each do |comment|
|
|
74
75
|
comment.to_xml_string str
|
|
75
76
|
end
|
|
76
77
|
str << '</commentList></comments>'
|
|
77
|
-
|
|
78
78
|
end
|
|
79
|
-
|
|
80
79
|
end
|
|
81
|
-
|
|
82
80
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Axlsx
|
|
2
4
|
# Conditional formatting allows styling of ranges based on functions
|
|
3
5
|
#
|
|
@@ -5,13 +7,12 @@ module Axlsx
|
|
|
5
7
|
# @see Worksheet#add_conditional_formatting
|
|
6
8
|
# @see ConditionalFormattingRule
|
|
7
9
|
class ConditionalFormatting
|
|
10
|
+
include Axlsx::OptionsParser
|
|
8
11
|
|
|
9
|
-
include Axlsx::OptionsParser
|
|
10
|
-
|
|
11
12
|
# Creates a new {ConditionalFormatting} object
|
|
12
13
|
# @option options [Array] rules The rules to apply
|
|
13
14
|
# @option options [String] sqref The range to apply the rules to
|
|
14
|
-
def initialize(options={})
|
|
15
|
+
def initialize(options = {})
|
|
15
16
|
@rules = []
|
|
16
17
|
parse_options options
|
|
17
18
|
end
|
|
@@ -28,7 +29,7 @@ module Axlsx
|
|
|
28
29
|
# @return [Array]
|
|
29
30
|
attr_reader :rules
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
# Add Conditional Formatting Rules to this object. Rules can either
|
|
32
33
|
# be already created {ConditionalFormattingRule} elements or
|
|
33
34
|
# hashes of options for automatic creation. If rules is a hash
|
|
34
35
|
# instead of an array, assume only one rule being added.
|
|
@@ -60,9 +61,15 @@ module Axlsx
|
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
# @see rules
|
|
63
|
-
def rules=(v)
|
|
64
|
+
def rules=(v)
|
|
65
|
+
@rules = v
|
|
66
|
+
end
|
|
67
|
+
|
|
64
68
|
# @see sqref
|
|
65
|
-
def sqref=(v)
|
|
69
|
+
def sqref=(v)
|
|
70
|
+
Axlsx.validate_string(v)
|
|
71
|
+
@sqref = v
|
|
72
|
+
end
|
|
66
73
|
|
|
67
74
|
# Serializes the conditional formatting element
|
|
68
75
|
# @example Conditional Formatting XML looks like:
|
|
@@ -73,9 +80,12 @@ module Axlsx
|
|
|
73
80
|
# </conditionalFormatting>
|
|
74
81
|
# @param [String] str
|
|
75
82
|
# @return [String]
|
|
76
|
-
def to_xml_string(str = '')
|
|
77
|
-
str <<
|
|
78
|
-
|
|
83
|
+
def to_xml_string(str = +'')
|
|
84
|
+
str << '<conditionalFormatting sqref="' << sqref << '">'
|
|
85
|
+
rules.each_with_index do |rule, index|
|
|
86
|
+
str << ' ' unless index == 0
|
|
87
|
+
rule.to_xml_string(str)
|
|
88
|
+
end
|
|
79
89
|
str << '</conditionalFormatting>'
|
|
80
90
|
end
|
|
81
91
|
end
|