caxlsx 3.4.0 → 4.0.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 +16 -0
- data/README.md +11 -12
- data/Rakefile +7 -5
- data/lib/axlsx/content_type/abstract_content_type.rb +9 -4
- data/lib/axlsx/content_type/content_type.rb +7 -5
- data/lib/axlsx/content_type/default.rb +4 -2
- data/lib/axlsx/content_type/override.rb +4 -2
- data/lib/axlsx/doc_props/app.rb +26 -24
- 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 +12 -10
- data/lib/axlsx/drawing/ax_data_source.rb +2 -0
- data/lib/axlsx/drawing/axes.rb +6 -4
- data/lib/axlsx/drawing/axis.rb +21 -19
- 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 +8 -6
- 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 +12 -10
- data/lib/axlsx/drawing/chart.rb +20 -18
- data/lib/axlsx/drawing/d_lbls.rb +7 -5
- data/lib/axlsx/drawing/drawing.rb +58 -56
- data/lib/axlsx/drawing/graphic_frame.rb +6 -4
- data/lib/axlsx/drawing/hyperlink.rb +10 -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 +12 -10
- data/lib/axlsx/drawing/marker.rb +9 -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 +7 -5
- data/lib/axlsx/drawing/pic.rb +16 -14
- data/lib/axlsx/drawing/picture_locking.rb +3 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -3
- data/lib/axlsx/drawing/pie_series.rb +8 -6
- data/lib/axlsx/drawing/scaling.rb +8 -6
- 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 +7 -5
- data/lib/axlsx/drawing/series.rb +6 -4
- 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 +9 -7
- data/lib/axlsx/drawing/vml_drawing.rb +18 -16
- data/lib/axlsx/drawing/vml_shape.rb +24 -22
- data/lib/axlsx/package.rb +69 -66
- data/lib/axlsx/rels/relationship.rb +10 -5
- data/lib/axlsx/rels/relationships.rb +5 -3
- data/lib/axlsx/stylesheet/border.rb +6 -4
- data/lib/axlsx/stylesheet/border_pr.rb +5 -3
- data/lib/axlsx/stylesheet/cell_alignment.rb +12 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +5 -3
- data/lib/axlsx/stylesheet/cell_style.rb +10 -8
- data/lib/axlsx/stylesheet/color.rb +9 -7
- data/lib/axlsx/stylesheet/dxf.rb +5 -3
- data/lib/axlsx/stylesheet/fill.rb +3 -1
- data/lib/axlsx/stylesheet/font.rb +18 -16
- data/lib/axlsx/stylesheet/gradient_fill.rb +6 -4
- data/lib/axlsx/stylesheet/gradient_stop.rb +6 -4
- data/lib/axlsx/stylesheet/num_fmt.rb +8 -10
- data/lib/axlsx/stylesheet/pattern_fill.rb +5 -3
- data/lib/axlsx/stylesheet/styles.rb +69 -71
- data/lib/axlsx/stylesheet/table_style.rb +7 -5
- data/lib/axlsx/stylesheet/table_style_element.rb +6 -4
- data/lib/axlsx/stylesheet/table_styles.rb +6 -4
- data/lib/axlsx/stylesheet/xf.rb +18 -16
- data/lib/axlsx/util/accessors.rb +4 -2
- 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 +3 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
- data/lib/axlsx/workbook/workbook.rb +78 -76
- data/lib/axlsx/workbook/workbook_view.rb +3 -1
- data/lib/axlsx/workbook/workbook_views.rb +3 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +7 -3
- 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 +55 -48
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
- data/lib/axlsx/workbook/worksheet/cfvo.rb +5 -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 +5 -3
- data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
- data/lib/axlsx/workbook/worksheet/cols.rb +3 -1
- 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 +9 -4
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +18 -16
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
- data/lib/axlsx/workbook/worksheet/data_validation.rb +30 -28
- data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -1
- 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 +23 -6
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +5 -5
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_margins.rb +15 -10
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_setup.rb +11 -9
- data/lib/axlsx/workbook/worksheet/pane.rb +11 -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 +2 -0
- 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 +5 -3
- data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +16 -14
- data/lib/axlsx/workbook/worksheet/row.rb +6 -7
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +6 -4
- data/lib/axlsx/workbook/worksheet/selection.rb +9 -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 +10 -8
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +15 -13
- 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 +3 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -37
- 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 +6 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -2
- data/lib/axlsx.rb +56 -42
- data/lib/caxlsx.rb +3 -1
- metadata +49 -43
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A simple list of merged cells
|
3
5
|
class MergedCells < SimpleTypedList
|
@@ -10,23 +12,21 @@ module Axlsx
|
|
10
12
|
end
|
11
13
|
|
12
14
|
# adds cells to the merged cells collection
|
13
|
-
# @param [Array
|
15
|
+
# @param [Array|String] cells The cells to add to the merged cells
|
14
16
|
# collection. This can be an array of actual cells or a string style
|
15
17
|
# range like 'A1:C1'
|
16
18
|
def add(cells)
|
17
19
|
self << if cells.is_a?(String)
|
18
20
|
cells
|
19
21
|
elsif cells.is_a?(Array)
|
20
|
-
Axlsx
|
21
|
-
elsif cells.is_a?(Row)
|
22
|
-
Axlsx::cell_range(cells, false)
|
22
|
+
Axlsx.cell_range(cells, false)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
# serialize the object
|
27
27
|
# @param [String] str
|
28
28
|
# @return [String]
|
29
|
-
def to_xml_string(str = '')
|
29
|
+
def to_xml_string(str = +'')
|
30
30
|
return if empty?
|
31
31
|
|
32
32
|
str << "<mergeCells count='#{size}'>"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The OutlinePr class manages serialization of a worksheet's outlinePr element, which provides various
|
3
5
|
# options to control outlining.
|
@@ -25,8 +27,10 @@ module Axlsx
|
|
25
27
|
# Serialize the object
|
26
28
|
# @param [String] str serialized output will be appended to this object if provided.
|
27
29
|
# @return [String]
|
28
|
-
def to_xml_string(str = '')
|
29
|
-
str <<
|
30
|
+
def to_xml_string(str = +'')
|
31
|
+
str << '<outlinePr '
|
32
|
+
serialized_attributes(str)
|
33
|
+
str << '/>'
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# PageMargins specify the margins when printing a worksheet.
|
3
5
|
#
|
@@ -27,7 +29,10 @@ module Axlsx
|
|
27
29
|
parse_options options
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
# Possible margins to set
|
33
|
+
MARGIN_KEYS = [:left, :right, :top, :bottom, :header, :footer].freeze
|
34
|
+
|
35
|
+
serializable_attributes(*MARGIN_KEYS)
|
31
36
|
|
32
37
|
# Default left and right margin (in inches)
|
33
38
|
DEFAULT_LEFT_RIGHT = 0.75
|
@@ -63,34 +68,34 @@ module Axlsx
|
|
63
68
|
attr_reader :footer
|
64
69
|
|
65
70
|
# Set some or all margins at once.
|
66
|
-
# @param [Hash] margins the margins to set
|
71
|
+
# @param [Hash] margins the margins to set. See {MARGIN_KEYS} for a list of possible keys.
|
67
72
|
def set(margins)
|
68
73
|
margins.select do |k, v|
|
69
|
-
next unless
|
74
|
+
next unless MARGIN_KEYS.include? k
|
70
75
|
|
71
76
|
send("#{k}=", v)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
75
80
|
# @see left
|
76
|
-
def left=(v); Axlsx
|
81
|
+
def left=(v); Axlsx.validate_unsigned_numeric(v); @left = v end
|
77
82
|
# @see right
|
78
|
-
def right=(v); Axlsx
|
83
|
+
def right=(v); Axlsx.validate_unsigned_numeric(v); @right = v end
|
79
84
|
# @see top
|
80
|
-
def top=(v); Axlsx
|
85
|
+
def top=(v); Axlsx.validate_unsigned_numeric(v); @top = v end
|
81
86
|
# @see bottom
|
82
|
-
def bottom=(v); Axlsx
|
87
|
+
def bottom=(v); Axlsx.validate_unsigned_numeric(v); @bottom = v end
|
83
88
|
# @see header
|
84
|
-
def header=(v); Axlsx
|
89
|
+
def header=(v); Axlsx.validate_unsigned_numeric(v); @header = v end
|
85
90
|
# @see footer
|
86
|
-
def footer=(v); Axlsx
|
91
|
+
def footer=(v); Axlsx.validate_unsigned_numeric(v); @footer = v end
|
87
92
|
|
88
93
|
# Serializes the page margins element
|
89
94
|
# @param [String] str
|
90
95
|
# @return [String]
|
91
96
|
# @note For compatibility, this is a noop unless custom margins have been specified.
|
92
97
|
# @see #custom_margins_specified?
|
93
|
-
def to_xml_string(str = '')
|
98
|
+
def to_xml_string(str = +'')
|
94
99
|
serialized_tag('pageMargins', str)
|
95
100
|
end
|
96
101
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Page setup properties of the worksheet
|
3
5
|
# This class name is not a typo, its spec.
|
@@ -35,8 +37,10 @@ module Axlsx
|
|
35
37
|
end
|
36
38
|
|
37
39
|
# serialize to xml
|
38
|
-
def to_xml_string(str = '')
|
39
|
-
str <<
|
40
|
+
def to_xml_string(str = +'')
|
41
|
+
str << '<pageSetUpPr '
|
42
|
+
serialized_attributes(str)
|
43
|
+
str << '/>'
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Page setup settings for printing a worksheet. All settings are optional.
|
3
5
|
#
|
@@ -196,17 +198,17 @@ module Axlsx
|
|
196
198
|
end
|
197
199
|
|
198
200
|
# @see fit_to_height
|
199
|
-
def fit_to_height=(v); Axlsx
|
201
|
+
def fit_to_height=(v); Axlsx.validate_unsigned_int(v); @fit_to_height = v; end
|
200
202
|
# @see fit_to_width
|
201
|
-
def fit_to_width=(v); Axlsx
|
203
|
+
def fit_to_width=(v); Axlsx.validate_unsigned_int(v); @fit_to_width = v; end
|
202
204
|
# @see orientation
|
203
|
-
def orientation=(v); Axlsx
|
205
|
+
def orientation=(v); Axlsx.validate_page_orientation(v); @orientation = v; end
|
204
206
|
# @see paper_height
|
205
|
-
def paper_height=(v); Axlsx
|
207
|
+
def paper_height=(v); Axlsx.validate_number_with_unit(v); @paper_height = v; end
|
206
208
|
# @see paper_width
|
207
|
-
def paper_width=(v); Axlsx
|
209
|
+
def paper_width=(v); Axlsx.validate_number_with_unit(v); @paper_width = v; end
|
208
210
|
# @see scale
|
209
|
-
def scale=(v); Axlsx
|
211
|
+
def scale=(v); Axlsx.validate_scale_10_400(v); @scale = v; end
|
210
212
|
|
211
213
|
# convenience method to achieve sanity when setting fit_to_width and fit_to_height
|
212
214
|
# as they both default to 1 if only their counterpart is specified.
|
@@ -223,14 +225,14 @@ module Axlsx
|
|
223
225
|
# We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.
|
224
226
|
# @return [Boolean]
|
225
227
|
def fit_to_page?
|
226
|
-
# is there some better
|
227
|
-
(fit_to_width
|
228
|
+
# is there some better way to express this?
|
229
|
+
(!fit_to_width.nil? || !fit_to_height.nil?)
|
228
230
|
end
|
229
231
|
|
230
232
|
# Serializes the page settings element.
|
231
233
|
# @param [String] str
|
232
234
|
# @return [String]
|
233
|
-
def to_xml_string(str = '')
|
235
|
+
def to_xml_string(str = +'')
|
234
236
|
serialized_tag('pageSetup', str)
|
235
237
|
end
|
236
238
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Pane options for a worksheet.
|
3
5
|
#
|
@@ -94,33 +96,33 @@ module Axlsx
|
|
94
96
|
|
95
97
|
# @see active_pane
|
96
98
|
def active_pane=(v)
|
97
|
-
Axlsx
|
98
|
-
@active_pane = Axlsx
|
99
|
+
Axlsx.validate_pane_type(v)
|
100
|
+
@active_pane = Axlsx.camel(v.to_s, false)
|
99
101
|
end
|
100
102
|
|
101
103
|
# @see state
|
102
104
|
def state=(v)
|
103
|
-
Axlsx
|
104
|
-
@state = Axlsx
|
105
|
+
Axlsx.validate_split_state_type(v)
|
106
|
+
@state = Axlsx.camel(v.to_s, false)
|
105
107
|
end
|
106
108
|
|
107
109
|
# @see top_left_cell
|
108
110
|
def top_left_cell=(v)
|
109
|
-
cell = (v.
|
110
|
-
Axlsx
|
111
|
+
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
|
112
|
+
Axlsx.validate_string(cell)
|
111
113
|
@top_left_cell = cell
|
112
114
|
end
|
113
115
|
|
114
116
|
# @see x_split
|
115
|
-
def x_split=(v); Axlsx
|
117
|
+
def x_split=(v); Axlsx.validate_unsigned_int(v); @x_split = v end
|
116
118
|
|
117
119
|
# @see y_split
|
118
|
-
def y_split=(v); Axlsx
|
120
|
+
def y_split=(v); Axlsx.validate_unsigned_int(v); @y_split = v end
|
119
121
|
|
120
122
|
# Serializes the data validation
|
121
123
|
# @param [String] str
|
122
124
|
# @return [String]
|
123
|
-
def to_xml_string(str = '')
|
125
|
+
def to_xml_string(str = +'')
|
124
126
|
finalize
|
125
127
|
serialized_tag 'pane', str
|
126
128
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Table
|
3
5
|
# @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
|
@@ -122,7 +124,7 @@ module Axlsx
|
|
122
124
|
@data = []
|
123
125
|
v.each do |data_field|
|
124
126
|
if data_field.is_a? String
|
125
|
-
data_field = { :
|
127
|
+
data_field = { ref: data_field }
|
126
128
|
end
|
127
129
|
data_field.each do |key, value|
|
128
130
|
if key == :num_fmt
|
@@ -133,7 +135,6 @@ module Axlsx
|
|
133
135
|
end
|
134
136
|
@data << data_field
|
135
137
|
end
|
136
|
-
@data
|
137
138
|
end
|
138
139
|
|
139
140
|
# The pages
|
@@ -158,13 +159,13 @@ module Axlsx
|
|
158
159
|
# The part name for this table
|
159
160
|
# @return [String]
|
160
161
|
def pn
|
161
|
-
|
162
|
+
format(PIVOT_TABLE_PN, index + 1)
|
162
163
|
end
|
163
164
|
|
164
165
|
# The relationship part name of this pivot table
|
165
166
|
# @return [String]
|
166
167
|
def rels_pn
|
167
|
-
|
168
|
+
format(PIVOT_TABLE_RELS_PN, index + 1)
|
168
169
|
end
|
169
170
|
|
170
171
|
# The cache_definition for this pivot table
|
@@ -184,13 +185,13 @@ module Axlsx
|
|
184
185
|
# Serializes the object
|
185
186
|
# @param [String] str
|
186
187
|
# @return [String]
|
187
|
-
def to_xml_string(str = '')
|
188
|
+
def to_xml_string(str = +'')
|
188
189
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
189
190
|
|
190
|
-
str <<
|
191
|
+
str << '<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"' << (data.size <= 1 ? ' dataOnRows="1"' : '') << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">'
|
191
192
|
|
192
|
-
str <<
|
193
|
-
str <<
|
193
|
+
str << '<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>'
|
194
|
+
str << '<pivotFields count="' << header_cells_count.to_s << '">'
|
194
195
|
|
195
196
|
header_cell_values.each do |cell_value|
|
196
197
|
subtotal = !no_subtotals_on_headers.include?(cell_value)
|
@@ -203,13 +204,13 @@ module Axlsx
|
|
203
204
|
str << '<rowFields count="1"><field x="-2"/></rowFields>'
|
204
205
|
str << '<rowItems count="2"><i><x/></i> <i i="1"><x v="1"/></i></rowItems>'
|
205
206
|
else
|
206
|
-
str <<
|
207
|
+
str << '<rowFields count="' << rows.size.to_s << '">'
|
207
208
|
rows.each do |row_value|
|
208
|
-
str <<
|
209
|
+
str << '<field x="' << header_index_of(row_value).to_s << '"/>'
|
209
210
|
end
|
210
211
|
str << '</rowFields>'
|
211
|
-
str <<
|
212
|
-
rows.size.times do
|
212
|
+
str << '<rowItems count="' << rows.size.to_s << '">'
|
213
|
+
rows.size.times do
|
213
214
|
str << '<i/>'
|
214
215
|
end
|
215
216
|
str << '</rowItems>'
|
@@ -219,7 +220,7 @@ module Axlsx
|
|
219
220
|
str << '<colFields count="1"><field x="-2"/></colFields>'
|
220
221
|
str << "<colItems count=\"#{data.size}\">"
|
221
222
|
str << '<i><x/></i>'
|
222
|
-
data
|
223
|
+
(data.size - 1).times do |i|
|
223
224
|
str << "<i i=\"#{i + 1}\"><x v=\"#{i + 1}\"/></i>"
|
224
225
|
end
|
225
226
|
str << '</colItems>'
|
@@ -227,16 +228,16 @@ module Axlsx
|
|
227
228
|
str << '<colItems count="1"><i/></colItems>'
|
228
229
|
end
|
229
230
|
else
|
230
|
-
str <<
|
231
|
+
str << '<colFields count="' << columns.size.to_s << '">'
|
231
232
|
columns.each do |column_value|
|
232
|
-
str <<
|
233
|
+
str << '<field x="' << header_index_of(column_value).to_s << '"/>'
|
233
234
|
end
|
234
235
|
str << '</colFields>'
|
235
236
|
end
|
236
237
|
unless pages.empty?
|
237
|
-
str <<
|
238
|
+
str << '<pageFields count="' << pages.size.to_s << '">'
|
238
239
|
pages.each do |page_value|
|
239
|
-
str <<
|
240
|
+
str << '<pageField fld="' << header_index_of(page_value).to_s << '"/>'
|
240
241
|
end
|
241
242
|
str << '</pageFields>'
|
242
243
|
end
|
@@ -244,7 +245,7 @@ module Axlsx
|
|
244
245
|
str << "<dataFields count=\"#{data.size}\">"
|
245
246
|
data.each do |datum_value|
|
246
247
|
# The correct name prefix in ["Sum","Average", etc...]
|
247
|
-
str << "<dataField name='#{
|
248
|
+
str << "<dataField name='#{datum_value[:subtotal] || ''} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
|
248
249
|
str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt]
|
249
250
|
str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
|
250
251
|
str << "/>"
|
@@ -265,7 +266,7 @@ module Axlsx
|
|
265
266
|
# References for header cells
|
266
267
|
# @return [Array]
|
267
268
|
def header_cell_refs
|
268
|
-
Axlsx
|
269
|
+
Axlsx.range_to_a(header_range).first
|
269
270
|
end
|
270
271
|
|
271
272
|
# The header cells for the pivot table
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Table
|
3
5
|
# @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
|
@@ -24,7 +26,7 @@ module Axlsx
|
|
24
26
|
# The part name for this table
|
25
27
|
# @return [String]
|
26
28
|
def pn
|
27
|
-
|
29
|
+
format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1)
|
28
30
|
end
|
29
31
|
|
30
32
|
# The identifier for this cache
|
@@ -43,15 +45,15 @@ module Axlsx
|
|
43
45
|
# Serializes the object
|
44
46
|
# @param [String] str
|
45
47
|
# @return [String]
|
46
|
-
def to_xml_string(str = '')
|
48
|
+
def to_xml_string(str = +'')
|
47
49
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
48
|
-
str <<
|
50
|
+
str << '<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">'
|
49
51
|
str << '<cacheSource type="worksheet">'
|
50
|
-
str <<
|
52
|
+
str << '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>'
|
51
53
|
str << '</cacheSource>'
|
52
|
-
str <<
|
54
|
+
str << '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">'
|
53
55
|
pivot_table.header_cells.each do |cell|
|
54
|
-
str <<
|
56
|
+
str << '<cacheField name="' << cell.clean_value << '" numFmtId="0">'
|
55
57
|
str << '<sharedItems count="0">'
|
56
58
|
str << '</sharedItems>'
|
57
59
|
str << '</cacheField>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Options for printing a worksheet. All options are boolean and false by default.
|
3
5
|
#
|
@@ -31,7 +33,7 @@ module Axlsx
|
|
31
33
|
# @note As all attributes default to "false" according to the xml schema definition, the generated xml includes only those attributes that are set to true.
|
32
34
|
# @param [String] str
|
33
35
|
# @return [String]
|
34
|
-
def to_xml_string(str = '')
|
36
|
+
def to_xml_string(str = +'')
|
35
37
|
serialized_tag 'printOptions', str
|
36
38
|
end
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The Protected Range class represents a set of cells in the worksheet
|
3
5
|
# @note the recommended way to manage protected ranges with via Worksheet#protect_range
|
@@ -39,7 +41,7 @@ module Axlsx
|
|
39
41
|
# @param [String] str if this string object is provided we append
|
40
42
|
# our output to that object. Use this - it helps limit the number of
|
41
43
|
# objects created during serialization
|
42
|
-
def to_xml_string(str =
|
44
|
+
def to_xml_string(str = +'')
|
43
45
|
serialized_tag 'protectedRange', str
|
44
46
|
end
|
45
47
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A self serializing collection of ranges that should be protected in
|
3
5
|
# the worksheet
|
@@ -17,16 +19,16 @@ module Axlsx
|
|
17
19
|
sqref = if cells.is_a?(String)
|
18
20
|
cells
|
19
21
|
elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
|
20
|
-
Axlsx
|
22
|
+
Axlsx.cell_range(cells, false)
|
21
23
|
end
|
22
|
-
self << ProtectedRange.new(:
|
24
|
+
self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
|
23
25
|
last
|
24
26
|
end
|
25
27
|
|
26
28
|
# Serializes the protected ranges
|
27
29
|
# @param [String] str
|
28
30
|
# @return [String]
|
29
|
-
def to_xml_string(str = '')
|
31
|
+
def to_xml_string(str = +'')
|
30
32
|
return if empty?
|
31
33
|
|
32
34
|
str << '<protectedRanges>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A simple, self serializing class for storing TextRuns
|
3
5
|
class RichText < SimpleTypedList
|
@@ -45,7 +47,7 @@ module Axlsx
|
|
45
47
|
# renders the RichTextRuns in this collection
|
46
48
|
# @param [String] str
|
47
49
|
# @return [String]
|
48
|
-
def to_xml_string(str = '')
|
50
|
+
def to_xml_string(str = +'')
|
49
51
|
each { |run| run.to_xml_string(str) }
|
50
52
|
str
|
51
53
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The RichTextRun class creates and self serializing text run.
|
3
5
|
class RichTextRun
|
@@ -128,7 +130,7 @@ module Axlsx
|
|
128
130
|
|
129
131
|
# @see u
|
130
132
|
def u=(v)
|
131
|
-
v = :single if
|
133
|
+
v = :single if v == true || v == 1 || v == :true || v == 'true'
|
132
134
|
set_run_style :validate_cell_u, :u, v
|
133
135
|
end
|
134
136
|
|
@@ -138,7 +140,7 @@ module Axlsx
|
|
138
140
|
|
139
141
|
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
|
140
142
|
def color=(v)
|
141
|
-
@color = v.is_a?(Color) ? v : Color.new(:
|
143
|
+
@color = v.is_a?(Color) ? v : Color.new(rgb: v)
|
142
144
|
end
|
143
145
|
|
144
146
|
# The inline sz property for the cell
|
@@ -197,30 +199,30 @@ module Axlsx
|
|
197
199
|
return unless INLINE_STYLES.include?(attr.to_sym)
|
198
200
|
|
199
201
|
Axlsx.send(validator, value) unless validator.nil?
|
200
|
-
|
202
|
+
instance_variable_set :"@#{attr}", value
|
201
203
|
end
|
202
204
|
|
203
205
|
# Serializes the RichTextRun
|
204
206
|
# @param [String] str
|
205
207
|
# @return [String]
|
206
|
-
def to_xml_string(str = '')
|
208
|
+
def to_xml_string(str = +'')
|
207
209
|
valid = RichTextRun::INLINE_STYLES
|
208
|
-
data =
|
209
|
-
data = data.select { |key, value| valid.include?(key)
|
210
|
+
data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
|
211
|
+
data = data.select { |key, value| !value.nil? && valid.include?(key) }
|
210
212
|
|
211
213
|
str << '<r><rPr>'
|
212
|
-
data.
|
214
|
+
data.each do |key, val|
|
213
215
|
case key
|
214
216
|
when :font_name
|
215
|
-
str <<
|
217
|
+
str << '<rFont val="' << font_name << '"/>'
|
216
218
|
when :color
|
217
|
-
str <<
|
219
|
+
str << val.to_xml_string
|
218
220
|
else
|
219
|
-
str <<
|
221
|
+
str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
|
220
222
|
end
|
221
223
|
end
|
222
|
-
clean_value = Axlsx
|
223
|
-
str <<
|
224
|
+
clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
|
225
|
+
str << '</rPr><t>' << clean_value << '</t></r>'
|
224
226
|
end
|
225
227
|
|
226
228
|
private
|
@@ -240,7 +242,7 @@ module Axlsx
|
|
240
242
|
return sz if sz
|
241
243
|
|
242
244
|
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
|
243
|
-
|
245
|
+
font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
|
244
246
|
end
|
245
247
|
|
246
248
|
def style
|
@@ -253,7 +255,7 @@ module Axlsx
|
|
253
255
|
|
254
256
|
# Converts the value to the correct XML representation (fixes issues with
|
255
257
|
# Numbers)
|
256
|
-
def xml_value
|
258
|
+
def xml_value(value)
|
257
259
|
if value == true
|
258
260
|
1
|
259
261
|
elsif value == false
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A Row is a single row in a worksheet.
|
3
5
|
# @note The recommended way to manage rows and cells is to use Worksheet#add_row
|
@@ -86,12 +88,9 @@ module Axlsx
|
|
86
88
|
# @param [Integer] r_index The row index, 0 based.
|
87
89
|
# @param [String] str The string this rows xml will be appended to.
|
88
90
|
# @return [String]
|
89
|
-
def to_xml_string(r_index, str = '')
|
90
|
-
serialized_tag('row', str, :
|
91
|
-
|
92
|
-
# time..
|
93
|
-
each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, tmp) }
|
94
|
-
str << tmp
|
91
|
+
def to_xml_string(r_index, str = +'')
|
92
|
+
serialized_tag('row', str, r: Axlsx.row_ref(r_index)) do
|
93
|
+
each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
@@ -130,7 +129,7 @@ module Axlsx
|
|
130
129
|
# @see height
|
131
130
|
def height=(v)
|
132
131
|
unless v.nil?
|
133
|
-
Axlsx
|
132
|
+
Axlsx.validate_unsigned_numeric(v)
|
134
133
|
@custom_height = true
|
135
134
|
@ht = v
|
136
135
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A collection of break objects that define row breaks (page breaks) for printing and preview
|
3
5
|
|
@@ -11,8 +13,8 @@ module Axlsx
|
|
11
13
|
# max and man values are fixed.
|
12
14
|
# @see Break
|
13
15
|
def add_break(options)
|
14
|
-
# force feed the
|
15
|
-
self << Break.new(options.merge(:
|
16
|
+
# force feed the Excel default
|
17
|
+
self << Break.new(options.merge(max: 16383, man: true))
|
16
18
|
last
|
17
19
|
end
|
18
20
|
|
@@ -21,10 +23,10 @@ module Axlsx
|
|
21
23
|
# <brk id="7" max="16383" man="1"/>
|
22
24
|
# <brk id="13" max="16383" man="1"/>
|
23
25
|
# </rowBreaks>
|
24
|
-
def to_xml_string(str = '')
|
26
|
+
def to_xml_string(str = +'')
|
25
27
|
return if empty?
|
26
28
|
|
27
|
-
str <<
|
29
|
+
str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
|
28
30
|
each { |brk| brk.to_xml_string(str) }
|
29
31
|
str << '</rowBreaks>'
|
30
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Selection options for worksheet panes.
|
3
5
|
#
|
@@ -72,27 +74,27 @@ module Axlsx
|
|
72
74
|
|
73
75
|
# @see active_cell
|
74
76
|
def active_cell=(v)
|
75
|
-
cell = (v.
|
76
|
-
Axlsx
|
77
|
+
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
|
78
|
+
Axlsx.validate_string(cell)
|
77
79
|
@active_cell = cell
|
78
80
|
end
|
79
81
|
|
80
82
|
# @see active_cell_id
|
81
|
-
def active_cell_id=(v); Axlsx
|
83
|
+
def active_cell_id=(v); Axlsx.validate_unsigned_int(v); @active_cell_id = v end
|
82
84
|
|
83
85
|
# @see pane
|
84
86
|
def pane=(v)
|
85
|
-
Axlsx
|
86
|
-
@pane = Axlsx
|
87
|
+
Axlsx.validate_pane_type(v)
|
88
|
+
@pane = Axlsx.camel(v, false)
|
87
89
|
end
|
88
90
|
|
89
91
|
# @see sqref
|
90
|
-
def sqref=(v); Axlsx
|
92
|
+
def sqref=(v); Axlsx.validate_string(v); @sqref = v end
|
91
93
|
|
92
94
|
# Serializes the data validation
|
93
95
|
# @param [String] str
|
94
96
|
# @return [String]
|
95
|
-
def to_xml_string(str = '')
|
97
|
+
def to_xml_string(str = +'')
|
96
98
|
serialized_tag 'selection', str
|
97
99
|
end
|
98
100
|
end
|