caxlsx 3.4.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -1
- data/README.md +9 -11
- data/Rakefile +7 -5
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
- data/lib/axlsx/content_type/content_type.rb +8 -6
- data/lib/axlsx/content_type/default.rb +7 -2
- data/lib/axlsx/content_type/override.rb +7 -2
- data/lib/axlsx/doc_props/app.rb +95 -26
- data/lib/axlsx/doc_props/core.rb +8 -6
- data/lib/axlsx/drawing/area_chart.rb +10 -8
- data/lib/axlsx/drawing/area_series.rb +20 -12
- data/lib/axlsx/drawing/ax_data_source.rb +2 -0
- data/lib/axlsx/drawing/axes.rb +6 -4
- data/lib/axlsx/drawing/axis.rb +42 -22
- data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
- data/lib/axlsx/drawing/bar_chart.rb +13 -11
- data/lib/axlsx/drawing/bar_series.rb +20 -9
- data/lib/axlsx/drawing/bubble_chart.rb +6 -4
- data/lib/axlsx/drawing/bubble_series.rb +8 -6
- data/lib/axlsx/drawing/cat_axis.rb +29 -12
- data/lib/axlsx/drawing/chart.rb +46 -20
- data/lib/axlsx/drawing/d_lbls.rb +10 -8
- data/lib/axlsx/drawing/drawing.rb +59 -56
- data/lib/axlsx/drawing/graphic_frame.rb +6 -4
- data/lib/axlsx/drawing/hyperlink.rb +19 -8
- data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
- data/lib/axlsx/drawing/line_chart.rb +10 -8
- data/lib/axlsx/drawing/line_series.rb +20 -12
- data/lib/axlsx/drawing/marker.rb +24 -7
- data/lib/axlsx/drawing/num_data.rb +9 -7
- data/lib/axlsx/drawing/num_data_source.rb +9 -7
- data/lib/axlsx/drawing/num_val.rb +7 -5
- data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
- data/lib/axlsx/drawing/pic.rb +26 -15
- data/lib/axlsx/drawing/picture_locking.rb +3 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +23 -9
- data/lib/axlsx/drawing/scaling.rb +25 -9
- data/lib/axlsx/drawing/scatter_chart.rb +7 -5
- data/lib/axlsx/drawing/scatter_series.rb +14 -12
- data/lib/axlsx/drawing/ser_axis.rb +13 -5
- data/lib/axlsx/drawing/series.rb +13 -5
- data/lib/axlsx/drawing/series_title.rb +6 -4
- data/lib/axlsx/drawing/str_data.rb +7 -5
- data/lib/axlsx/drawing/str_val.rb +6 -4
- data/lib/axlsx/drawing/title.rb +13 -14
- data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
- data/lib/axlsx/drawing/val_axis.rb +4 -2
- data/lib/axlsx/drawing/view_3D.rb +16 -8
- data/lib/axlsx/drawing/vml_drawing.rb +18 -16
- data/lib/axlsx/drawing/vml_shape.rb +24 -22
- data/lib/axlsx/package.rb +73 -67
- data/lib/axlsx/rels/relationship.rb +21 -6
- data/lib/axlsx/rels/relationships.rb +6 -4
- data/lib/axlsx/stylesheet/border.rb +15 -4
- data/lib/axlsx/stylesheet/border_pr.rb +19 -6
- data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
- data/lib/axlsx/stylesheet/cell_style.rb +33 -8
- data/lib/axlsx/stylesheet/color.rb +15 -7
- data/lib/axlsx/stylesheet/dxf.rb +34 -9
- data/lib/axlsx/stylesheet/fill.rb +7 -2
- data/lib/axlsx/stylesheet/font.rb +65 -17
- data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
- data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
- data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
- data/lib/axlsx/stylesheet/styles.rb +124 -82
- data/lib/axlsx/stylesheet/table_style.rb +19 -6
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
- data/lib/axlsx/stylesheet/table_styles.rb +14 -5
- data/lib/axlsx/stylesheet/xf.rb +73 -18
- data/lib/axlsx/util/accessors.rb +10 -6
- data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
- data/lib/axlsx/util/constants.rb +117 -104
- data/lib/axlsx/util/mime_type_utils.rb +3 -5
- data/lib/axlsx/util/options_parser.rb +3 -1
- data/lib/axlsx/util/serialized_attributes.rb +42 -17
- data/lib/axlsx/util/simple_typed_list.rb +47 -47
- data/lib/axlsx/util/storage.rb +11 -10
- data/lib/axlsx/util/validators.rb +101 -41
- data/lib/axlsx/util/zip_command.rb +10 -10
- data/lib/axlsx/version.rb +3 -1
- data/lib/axlsx/workbook/defined_name.rb +6 -4
- data/lib/axlsx/workbook/defined_names.rb +4 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
- data/lib/axlsx/workbook/workbook.rb +94 -79
- data/lib/axlsx/workbook/workbook_view.rb +3 -1
- data/lib/axlsx/workbook/workbook_views.rb +4 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
- data/lib/axlsx/workbook/worksheet/break.rb +3 -1
- data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
- data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
- data/lib/axlsx/workbook/worksheet/col.rb +5 -3
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
- data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
- data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
- data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
- data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
- data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
- data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
- data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
- data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
- data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
- data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
- data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
- data/lib/axlsx/workbook/worksheet/row.rb +11 -9
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
- data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
- data/lib/axlsx/workbook/worksheet/table.rb +9 -7
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
- data/lib/axlsx.rb +56 -42
- data/lib/caxlsx.rb +3 -1
- metadata +39 -71
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The Cell Serializer class contains the logic for serializing cells based on their type.
|
3
5
|
class CellSerializer
|
@@ -7,28 +9,30 @@ module Axlsx
|
|
7
9
|
# @param [Integer] column_index The index of the cell's column
|
8
10
|
# @param [String] str The string to apend serialization to.
|
9
11
|
# @return [String]
|
10
|
-
def to_xml_string(row_index, column_index, cell, str = '')
|
11
|
-
str <<
|
12
|
+
def to_xml_string(row_index, column_index, cell, str = +'')
|
13
|
+
str << '<c r="'
|
14
|
+
str << Axlsx.col_ref(column_index) << Axlsx.row_ref(row_index)
|
15
|
+
str << '" s="' << cell.style_str << '" '
|
12
16
|
return str << '/>' if cell.value.nil?
|
13
17
|
|
14
18
|
method = cell.type
|
15
|
-
|
19
|
+
send(method, cell, str)
|
16
20
|
str << '</c>'
|
17
21
|
end
|
18
22
|
|
19
23
|
# builds an xml text run based on this cells attributes.
|
20
24
|
# @param [String] str The string instance this run will be concated to.
|
21
25
|
# @return [String]
|
22
|
-
def run_xml_string(cell, str = '')
|
26
|
+
def run_xml_string(cell, str = +'')
|
23
27
|
if cell.is_text_run?
|
24
28
|
valid = RichTextRun::INLINE_STYLES - [:value, :type]
|
25
|
-
data =
|
26
|
-
data = data.select { |key, value| valid.include?(key)
|
29
|
+
data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym)
|
30
|
+
data = data.select { |key, value| !value.nil? && valid.include?(key) }
|
27
31
|
RichText.new(cell.value.to_s, data).to_xml_string(str)
|
28
32
|
elsif cell.contains_rich_text?
|
29
33
|
cell.value.to_xml_string(str)
|
30
34
|
else
|
31
|
-
str <<
|
35
|
+
str << '<t>' << cell.clean_value << '</t>'
|
32
36
|
end
|
33
37
|
str
|
34
38
|
end
|
@@ -37,7 +41,7 @@ module Axlsx
|
|
37
41
|
# @param [Cell] cell The cell that is being serialized
|
38
42
|
# @param [String] str The string the serialized content will be appended to.
|
39
43
|
# @return [String]
|
40
|
-
def iso_8601(cell, str = '')
|
44
|
+
def iso_8601(cell, str = +'')
|
41
45
|
value_serialization 'd', cell.value, str
|
42
46
|
end
|
43
47
|
|
@@ -45,23 +49,23 @@ module Axlsx
|
|
45
49
|
# @param [Cell] cell The cell that is being serialized
|
46
50
|
# @param [String] str The string the serialized content will be appended to.
|
47
51
|
# @return [String]
|
48
|
-
def date(cell, str = '')
|
49
|
-
value_serialization false, DateTimeConverter
|
52
|
+
def date(cell, str = +'')
|
53
|
+
value_serialization false, DateTimeConverter.date_to_serial(cell.value).to_s, str
|
50
54
|
end
|
51
55
|
|
52
56
|
# Serializes cells that are type time
|
53
57
|
# @param [Cell] cell The cell that is being serialized
|
54
58
|
# @param [String] str The string the serialized content will be appended to.
|
55
59
|
# @return [String]
|
56
|
-
def time(cell, str = '')
|
57
|
-
value_serialization false, DateTimeConverter
|
60
|
+
def time(cell, str = +'')
|
61
|
+
value_serialization false, DateTimeConverter.time_to_serial(cell.value).to_s, str
|
58
62
|
end
|
59
63
|
|
60
64
|
# Serializes cells that are type boolean
|
61
65
|
# @param [Cell] cell The cell that is being serialized
|
62
66
|
# @param [String] str The string the serialized content will be appended to.
|
63
67
|
# @return [String]
|
64
|
-
def boolean(cell, str = '')
|
68
|
+
def boolean(cell, str = +'')
|
65
69
|
value_serialization 'b', cell.value.to_s, str
|
66
70
|
end
|
67
71
|
|
@@ -69,7 +73,7 @@ module Axlsx
|
|
69
73
|
# @param [Cell] cell The cell that is being serialized
|
70
74
|
# @param [String] str The string the serialized content will be appended to.
|
71
75
|
# @return [String]
|
72
|
-
def float(cell, str = '')
|
76
|
+
def float(cell, str = +'')
|
73
77
|
numeric cell, str
|
74
78
|
end
|
75
79
|
|
@@ -77,7 +81,7 @@ module Axlsx
|
|
77
81
|
# @param [Cell] cell The cell that is being serialized
|
78
82
|
# @param [String] str The string the serialized content will be appended to.
|
79
83
|
# @return [String]
|
80
|
-
def integer(cell, str = '')
|
84
|
+
def integer(cell, str = +'')
|
81
85
|
numeric cell, str
|
82
86
|
end
|
83
87
|
|
@@ -85,25 +89,25 @@ module Axlsx
|
|
85
89
|
# @param [Cell] cell The cell that is being serialized
|
86
90
|
# @param [String] str The string the serialized content will be appended to.
|
87
91
|
# @return [String]
|
88
|
-
def formula_serialization(cell, str = '')
|
89
|
-
str <<
|
90
|
-
str <<
|
92
|
+
def formula_serialization(cell, str = +'')
|
93
|
+
str << 't="str"><f>' << cell.clean_value.delete_prefix(FORMULA_PREFIX) << '</f>'
|
94
|
+
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
|
91
95
|
end
|
92
96
|
|
93
97
|
# Serializes cells that are type array formula
|
94
98
|
# @param [Cell] cell The cell that is being serialized
|
95
99
|
# @param [String] str The string the serialized content will be appended to.
|
96
100
|
# @return [String]
|
97
|
-
def array_formula_serialization(cell, str = '')
|
98
|
-
str <<
|
99
|
-
str <<
|
101
|
+
def array_formula_serialization(cell, str = +'')
|
102
|
+
str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
|
103
|
+
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
|
100
104
|
end
|
101
105
|
|
102
106
|
# Serializes cells that are type inline_string
|
103
107
|
# @param [Cell] cell The cell that is being serialized
|
104
108
|
# @param [String] str The string the serialized content will be appended to.
|
105
109
|
# @return [String]
|
106
|
-
def inline_string_serialization(cell, str = '')
|
110
|
+
def inline_string_serialization(cell, str = +'')
|
107
111
|
str << 't="inlineStr"><is>'
|
108
112
|
run_xml_string cell, str
|
109
113
|
str << '</is>'
|
@@ -113,7 +117,7 @@ module Axlsx
|
|
113
117
|
# @param [Cell] cell The cell that is being serialized
|
114
118
|
# @param [String] str The string the serialized content will be appended to.
|
115
119
|
# @return [String]
|
116
|
-
def string(cell, str = '')
|
120
|
+
def string(cell, str = +'')
|
117
121
|
if cell.is_array_formula?
|
118
122
|
array_formula_serialization cell, str
|
119
123
|
elsif cell.is_formula?
|
@@ -151,13 +155,13 @@ module Axlsx
|
|
151
155
|
|
152
156
|
private
|
153
157
|
|
154
|
-
def numeric(cell, str = '')
|
158
|
+
def numeric(cell, str = +'')
|
155
159
|
value_serialization 'n', cell.value, str
|
156
160
|
end
|
157
161
|
|
158
|
-
def value_serialization(serialization_type, serialization_value, str = '')
|
159
|
-
str <<
|
160
|
-
str <<
|
162
|
+
def value_serialization(serialization_type, serialization_value, str = +'')
|
163
|
+
str << 't="' << serialization_type.to_s << '"' if serialization_type
|
164
|
+
str << '><v>' << serialization_value.to_s << '</v>'
|
161
165
|
end
|
162
166
|
end
|
163
167
|
end
|
@@ -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
|
@@ -38,10 +40,16 @@ module Axlsx
|
|
38
40
|
attr_reader :val
|
39
41
|
|
40
42
|
# @see type
|
41
|
-
def type=(v)
|
43
|
+
def type=(v)
|
44
|
+
Axlsx.validate_conditional_formatting_value_object_type(v)
|
45
|
+
@type = v
|
46
|
+
end
|
42
47
|
|
43
48
|
# @see gte
|
44
|
-
def gte=(v)
|
49
|
+
def gte=(v)
|
50
|
+
Axlsx.validate_boolean(v)
|
51
|
+
@gte = v
|
52
|
+
end
|
45
53
|
|
46
54
|
# @see val
|
47
55
|
def val=(v)
|
@@ -53,7 +61,7 @@ module Axlsx
|
|
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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A collection of Cfvo objects that initializes with the required
|
3
5
|
# first two items
|
@@ -9,7 +11,7 @@ module Axlsx
|
|
9
11
|
# Serialize the Cfvo object
|
10
12
|
# @param [String] str
|
11
13
|
# @return [String]
|
12
|
-
def to_xml_string(str = '')
|
14
|
+
def to_xml_string(str = +'')
|
13
15
|
each { |cfvo| cfvo.to_xml_string(str) }
|
14
16
|
end
|
15
17
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The Col class defines column attributes for columns in sheets.
|
3
5
|
class Col
|
@@ -86,7 +88,7 @@ module Axlsx
|
|
86
88
|
# @see Col#outline
|
87
89
|
def outline_level=(v)
|
88
90
|
Axlsx.validate_unsigned_numeric(v)
|
89
|
-
raise ArgumentError, 'outlineLevel must be between 0 and 7' unless
|
91
|
+
raise ArgumentError, 'outlineLevel must be between 0 and 7' unless v >= 0 && v <= 7
|
90
92
|
|
91
93
|
@outline_level = v
|
92
94
|
end
|
@@ -112,7 +114,7 @@ module Axlsx
|
|
112
114
|
# current @width value.
|
113
115
|
# TODO!!!
|
114
116
|
# Axlsx.validate_unsigned_numeric(v) unless v == nil
|
115
|
-
@custom_width = @best_fit = v
|
117
|
+
@custom_width = @best_fit = !v.nil?
|
116
118
|
@width = v.nil? ? v : [v, MAX_WIDTH].min
|
117
119
|
end
|
118
120
|
|
@@ -135,7 +137,7 @@ module Axlsx
|
|
135
137
|
# Serialize this columns data to an xml string
|
136
138
|
# @param [String] str
|
137
139
|
# @return [String]
|
138
|
-
def to_xml_string(str = '')
|
140
|
+
def to_xml_string(str = +'')
|
139
141
|
serialized_tag('col', str)
|
140
142
|
end
|
141
143
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A collection of Brake objects.
|
3
5
|
# Please do not use this class directly. Instead use
|
@@ -5,7 +7,7 @@ module Axlsx
|
|
5
7
|
class ColBreaks < SimpleTypedList
|
6
8
|
# Instantiates a new list restricted to Break types
|
7
9
|
def initialize
|
8
|
-
super
|
10
|
+
super(Break)
|
9
11
|
end
|
10
12
|
|
11
13
|
# A column break specific helper for adding a break.
|
@@ -14,7 +16,7 @@ module Axlsx
|
|
14
16
|
# Break will be passed to the created break object.
|
15
17
|
# @see Break
|
16
18
|
def add_break(options)
|
17
|
-
self << Break.new(options.merge(:
|
19
|
+
self << Break.new(options.merge(max: 1048575, man: true))
|
18
20
|
last
|
19
21
|
end
|
20
22
|
|
@@ -23,10 +25,10 @@ module Axlsx
|
|
23
25
|
# <colBreaks count="1" manualBreakCount="1">
|
24
26
|
# <brk id="3" max="1048575" man="1"/>
|
25
27
|
# </colBreaks>
|
26
|
-
def to_xml_string(str = '')
|
28
|
+
def to_xml_string(str = +'')
|
27
29
|
return if empty?
|
28
30
|
|
29
|
-
str <<
|
31
|
+
str << '<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
|
30
32
|
each { |brk| brk.to_xml_string(str) }
|
31
33
|
str << '</colBreaks>'
|
32
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.
|
@@ -10,8 +12,8 @@ module Axlsx
|
|
10
12
|
# These are the default conditional formatting value objects
|
11
13
|
# that define a two tone color gradient.
|
12
14
|
def default_cfvos
|
13
|
-
[{ :
|
14
|
-
{ :
|
15
|
+
[{ type: :min, val: 0, color: 'FFFF7128' },
|
16
|
+
{ type: :max, val: 0, color: 'FFFFEF9C' }]
|
15
17
|
end
|
16
18
|
|
17
19
|
# A builder for two tone color gradient
|
@@ -20,7 +22,7 @@ module Axlsx
|
|
20
22
|
# color_scale = Axlsx::ColorScale.two_tone
|
21
23
|
# @see examples/example.rb conditional formatting examples.
|
22
24
|
def two_tone
|
23
|
-
|
25
|
+
new
|
24
26
|
end
|
25
27
|
|
26
28
|
# A builder for three tone color gradient
|
@@ -29,9 +31,9 @@ module Axlsx
|
|
29
31
|
# color_scale = Axlsx::ColorScale.three_tone
|
30
32
|
# @see examples/example.rb conditional formatting examples.
|
31
33
|
def three_tone
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
new({ type: :min, val: 0, color: 'FFF8696B' },
|
35
|
+
{ type: :percent, val: '50', color: 'FFFFEB84' },
|
36
|
+
{ type: :max, val: 0, color: 'FF63BE7B' })
|
35
37
|
end
|
36
38
|
end
|
37
39
|
# A simple typed list of cfvos
|
@@ -66,9 +68,9 @@ module Axlsx
|
|
66
68
|
# @option [Any] val The value of the cfvo to add
|
67
69
|
# @option [String] The rgb color for the cfvo
|
68
70
|
def add(options = {})
|
69
|
-
value_objects << Cfvo.new(:
|
70
|
-
colors << Color.new(:
|
71
|
-
{ :
|
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 }
|
72
74
|
end
|
73
75
|
|
74
76
|
# removes the cfvo and color pair at the index specified.
|
@@ -82,7 +84,7 @@ module Axlsx
|
|
82
84
|
# Serialize this color_scale object data to an xml string
|
83
85
|
# @param [String] str
|
84
86
|
# @return [String]
|
85
|
-
def to_xml_string(str = '')
|
87
|
+
def to_xml_string(str = +'')
|
86
88
|
str << '<colorScale>'
|
87
89
|
value_objects.to_xml_string(str)
|
88
90
|
colors.each { |color| color.to_xml_string(str) }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The cols class manages the col object used to manage column widths.
|
3
5
|
# This is where the magic happens with autowidth
|
@@ -5,14 +7,14 @@ module Axlsx
|
|
5
7
|
def initialize(worksheet)
|
6
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
7
9
|
|
8
|
-
super
|
10
|
+
super(Col)
|
9
11
|
@worksheet = worksheet
|
10
12
|
end
|
11
13
|
|
12
14
|
# Serialize the Cols object
|
13
15
|
# @param [String] str
|
14
16
|
# @return [String]
|
15
|
-
def to_xml_string(str = '')
|
17
|
+
def to_xml_string(str = +'')
|
16
18
|
return if empty?
|
17
19
|
|
18
20
|
str << '<cols>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A comment is the text data for a comment
|
3
5
|
class Comment
|
@@ -59,17 +61,17 @@ module Axlsx
|
|
59
61
|
# serialize the object
|
60
62
|
# @param [String] str
|
61
63
|
# @return [String]
|
62
|
-
def to_xml_string(str =
|
64
|
+
def to_xml_string(str = +'')
|
63
65
|
author = @comments.authors[author_index]
|
64
|
-
str <<
|
66
|
+
str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
|
65
67
|
str << '<text>'
|
66
68
|
unless author.to_s == ""
|
67
69
|
str << '<r><rPr><b/><color indexed="81"/></rPr>'
|
68
|
-
str <<
|
70
|
+
str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
|
69
71
|
end
|
70
72
|
str << '<r>'
|
71
73
|
str << '<rPr><color indexed="81"/></rPr>'
|
72
|
-
str <<
|
74
|
+
str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
|
73
75
|
str << '</comment>'
|
74
76
|
end
|
75
77
|
|
@@ -78,8 +80,8 @@ module Axlsx
|
|
78
80
|
# initialize the vml shape based on this comment's ref/position in the worksheet.
|
79
81
|
# by default, all columns are 5 columns wide and 5 rows high
|
80
82
|
def initialize_vml_shape
|
81
|
-
pos = Axlsx
|
82
|
-
@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|
|
83
85
|
vml.left_column = vml.column
|
84
86
|
vml.right_column = vml.column + 2
|
85
87
|
vml.top_row = vml.row
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Comments is a collection of Comment objects for a worksheet
|
3
5
|
class Comments < SimpleTypedList
|
@@ -18,7 +20,7 @@ module Axlsx
|
|
18
20
|
# The part name for this object
|
19
21
|
# @return [String]
|
20
22
|
def pn
|
21
|
-
|
23
|
+
format(COMMENT_PN, index + 1)
|
22
24
|
end
|
23
25
|
|
24
26
|
# Creates a new Comments object
|
@@ -62,11 +64,11 @@ module Axlsx
|
|
62
64
|
# serialize the object
|
63
65
|
# @param [String] str
|
64
66
|
# @return [String]
|
65
|
-
def to_xml_string(str =
|
67
|
+
def to_xml_string(str = +'')
|
66
68
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
67
|
-
str <<
|
69
|
+
str << '<comments xmlns="' << XML_NS << '"><authors>'
|
68
70
|
authors.each do |author|
|
69
|
-
str <<
|
71
|
+
str << '<author>' << author.to_s << '</author>'
|
70
72
|
end
|
71
73
|
str << '</authors><commentList>'
|
72
74
|
each do |comment|
|
@@ -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
|
#
|
@@ -59,9 +61,15 @@ module Axlsx
|
|
59
61
|
end
|
60
62
|
|
61
63
|
# @see rules
|
62
|
-
def rules=(v)
|
64
|
+
def rules=(v)
|
65
|
+
@rules = v
|
66
|
+
end
|
67
|
+
|
63
68
|
# @see sqref
|
64
|
-
def sqref=(v)
|
69
|
+
def sqref=(v)
|
70
|
+
Axlsx.validate_string(v)
|
71
|
+
@sqref = v
|
72
|
+
end
|
65
73
|
|
66
74
|
# Serializes the conditional formatting element
|
67
75
|
# @example Conditional Formatting XML looks like:
|
@@ -72,9 +80,12 @@ module Axlsx
|
|
72
80
|
# </conditionalFormatting>
|
73
81
|
# @param [String] str
|
74
82
|
# @return [String]
|
75
|
-
def to_xml_string(str = '')
|
76
|
-
str <<
|
77
|
-
|
83
|
+
def to_xml_string(str = +'')
|
84
|
+
str << '<conditionalFormatting sqref="' << sqref << '">'
|
85
|
+
rules.each_with_index do |rule, index|
|
86
|
+
str << ' ' unless index.zero?
|
87
|
+
rule.to_xml_string(str)
|
88
|
+
end
|
78
89
|
str << '</conditionalFormatting>'
|
79
90
|
end
|
80
91
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Conditional formatting rules specify formulas whose evaluations
|
3
5
|
# format cells
|
@@ -153,33 +155,88 @@ module Axlsx
|
|
153
155
|
end
|
154
156
|
|
155
157
|
# @see type
|
156
|
-
def type=(v)
|
158
|
+
def type=(v)
|
159
|
+
Axlsx.validate_conditional_formatting_type(v)
|
160
|
+
@type = v
|
161
|
+
end
|
162
|
+
|
157
163
|
# @see aboveAverage
|
158
|
-
def aboveAverage=(v)
|
164
|
+
def aboveAverage=(v)
|
165
|
+
Axlsx.validate_boolean(v)
|
166
|
+
@aboveAverage = v
|
167
|
+
end
|
168
|
+
|
159
169
|
# @see bottom
|
160
|
-
def bottom=(v)
|
170
|
+
def bottom=(v)
|
171
|
+
Axlsx.validate_boolean(v)
|
172
|
+
@bottom = v
|
173
|
+
end
|
174
|
+
|
161
175
|
# @see dxfId
|
162
|
-
def dxfId=(v)
|
176
|
+
def dxfId=(v)
|
177
|
+
Axlsx.validate_unsigned_numeric(v)
|
178
|
+
@dxfId = v
|
179
|
+
end
|
180
|
+
|
163
181
|
# @see equalAverage
|
164
|
-
def equalAverage=(v)
|
182
|
+
def equalAverage=(v)
|
183
|
+
Axlsx.validate_boolean(v)
|
184
|
+
@equalAverage = v
|
185
|
+
end
|
186
|
+
|
165
187
|
# @see priority
|
166
|
-
def priority=(v)
|
188
|
+
def priority=(v)
|
189
|
+
Axlsx.validate_unsigned_numeric(v)
|
190
|
+
@priority = v
|
191
|
+
end
|
192
|
+
|
167
193
|
# @see operator
|
168
|
-
def operator=(v)
|
194
|
+
def operator=(v)
|
195
|
+
Axlsx.validate_conditional_formatting_operator(v)
|
196
|
+
@operator = v
|
197
|
+
end
|
198
|
+
|
169
199
|
# @see text
|
170
|
-
def text=(v)
|
200
|
+
def text=(v)
|
201
|
+
Axlsx.validate_string(v)
|
202
|
+
@text = v
|
203
|
+
end
|
204
|
+
|
171
205
|
# @see percent
|
172
|
-
def percent=(v)
|
206
|
+
def percent=(v)
|
207
|
+
Axlsx.validate_boolean(v)
|
208
|
+
@percent = v
|
209
|
+
end
|
210
|
+
|
173
211
|
# @see rank
|
174
|
-
def rank=(v)
|
212
|
+
def rank=(v)
|
213
|
+
Axlsx.validate_unsigned_numeric(v)
|
214
|
+
@rank = v
|
215
|
+
end
|
216
|
+
|
175
217
|
# @see stdDev
|
176
|
-
def stdDev=(v)
|
218
|
+
def stdDev=(v)
|
219
|
+
Axlsx.validate_unsigned_numeric(v)
|
220
|
+
@stdDev = v
|
221
|
+
end
|
222
|
+
|
177
223
|
# @see stopIfTrue
|
178
|
-
def stopIfTrue=(v)
|
224
|
+
def stopIfTrue=(v)
|
225
|
+
Axlsx.validate_boolean(v)
|
226
|
+
@stopIfTrue = v
|
227
|
+
end
|
228
|
+
|
179
229
|
# @see timePeriod
|
180
|
-
def timePeriod=(v)
|
230
|
+
def timePeriod=(v)
|
231
|
+
Axlsx.validate_time_period_type(v)
|
232
|
+
@timePeriod = v
|
233
|
+
end
|
234
|
+
|
181
235
|
# @see formula
|
182
|
-
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
|
183
240
|
|
184
241
|
# @see color_scale
|
185
242
|
def color_scale=(v)
|
@@ -202,11 +259,11 @@ module Axlsx
|
|
202
259
|
# Serializes the conditional formatting rule
|
203
260
|
# @param [String] str
|
204
261
|
# @return [String]
|
205
|
-
def to_xml_string(str = '')
|
262
|
+
def to_xml_string(str = +'')
|
206
263
|
str << '<cfRule '
|
207
264
|
serialized_attributes str
|
208
265
|
str << '>'
|
209
|
-
str <<
|
266
|
+
str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
|
210
267
|
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
|
211
268
|
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
|
212
269
|
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A simple, self serializing class for storing conditional formattings
|
3
5
|
class ConditionalFormattings < SimpleTypedList
|
@@ -5,7 +7,7 @@ module Axlsx
|
|
5
7
|
def initialize(worksheet)
|
6
8
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
7
9
|
|
8
|
-
super
|
10
|
+
super(ConditionalFormatting)
|
9
11
|
@worksheet = worksheet
|
10
12
|
end
|
11
13
|
|
@@ -14,7 +16,7 @@ module Axlsx
|
|
14
16
|
attr_reader :worksheet
|
15
17
|
|
16
18
|
# serialize the conditional formattings
|
17
|
-
def to_xml_string(str =
|
19
|
+
def to_xml_string(str = +'')
|
18
20
|
return if empty?
|
19
21
|
|
20
22
|
each { |item| item.to_xml_string(str) }
|