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,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# The RichTextRun class creates and self serializing text run.
|
|
4
5
|
class RichTextRun
|
|
5
|
-
|
|
6
6
|
include Axlsx::OptionsParser
|
|
7
7
|
|
|
8
8
|
attr_reader :value
|
|
@@ -13,7 +13,7 @@ module Axlsx
|
|
|
13
13
|
:shadow, :condense, :extend, :u,
|
|
14
14
|
:vertAlign, :sz, :color, :scheme].freeze
|
|
15
15
|
|
|
16
|
-
def initialize(value, options={})
|
|
16
|
+
def initialize(value, options = {})
|
|
17
17
|
self.value = value
|
|
18
18
|
parse_options(options)
|
|
19
19
|
end
|
|
@@ -27,8 +27,11 @@ module Axlsx
|
|
|
27
27
|
# The inline font_name property for the cell
|
|
28
28
|
# @return [String]
|
|
29
29
|
attr_reader :font_name
|
|
30
|
+
|
|
30
31
|
# @see font_name
|
|
31
|
-
def font_name=(v)
|
|
32
|
+
def font_name=(v)
|
|
33
|
+
set_run_style :validate_string, :font_name, v
|
|
34
|
+
end
|
|
32
35
|
|
|
33
36
|
# The inline charset property for the cell
|
|
34
37
|
# As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
|
|
@@ -53,8 +56,11 @@ module Axlsx
|
|
|
53
56
|
# 255  OEM_CHARSET
|
|
54
57
|
# @return [String]
|
|
55
58
|
attr_reader :charset
|
|
59
|
+
|
|
56
60
|
# @see charset
|
|
57
|
-
def charset=(v)
|
|
61
|
+
def charset=(v)
|
|
62
|
+
set_run_style :validate_unsigned_int, :charset, v
|
|
63
|
+
end
|
|
58
64
|
|
|
59
65
|
# The inline family property for the cell
|
|
60
66
|
# @return [Integer]
|
|
@@ -64,6 +70,7 @@ module Axlsx
|
|
|
64
70
|
# 4 Script
|
|
65
71
|
# 5 Decorative
|
|
66
72
|
attr_reader :family
|
|
73
|
+
|
|
67
74
|
# @see family
|
|
68
75
|
def family=(v)
|
|
69
76
|
set_run_style :validate_family, :family, v.to_i
|
|
@@ -72,75 +79,102 @@ module Axlsx
|
|
|
72
79
|
# The inline bold property for the cell
|
|
73
80
|
# @return [Boolean]
|
|
74
81
|
attr_reader :b
|
|
82
|
+
|
|
75
83
|
# @see b
|
|
76
|
-
def b=(v)
|
|
84
|
+
def b=(v)
|
|
85
|
+
set_run_style :validate_boolean, :b, v
|
|
86
|
+
end
|
|
77
87
|
|
|
78
88
|
# The inline italic property for the cell
|
|
79
89
|
# @return [Boolean]
|
|
80
90
|
attr_reader :i
|
|
91
|
+
|
|
81
92
|
# @see i
|
|
82
|
-
def i=(v)
|
|
93
|
+
def i=(v)
|
|
94
|
+
set_run_style :validate_boolean, :i, v
|
|
95
|
+
end
|
|
83
96
|
|
|
84
97
|
# The inline strike property for the cell
|
|
85
98
|
# @return [Boolean]
|
|
86
99
|
attr_reader :strike
|
|
100
|
+
|
|
87
101
|
# @see strike
|
|
88
|
-
def strike=(v)
|
|
102
|
+
def strike=(v)
|
|
103
|
+
set_run_style :validate_boolean, :strike, v
|
|
104
|
+
end
|
|
89
105
|
|
|
90
106
|
# The inline outline property for the cell
|
|
91
107
|
# @return [Boolean]
|
|
92
108
|
attr_reader :outline
|
|
109
|
+
|
|
93
110
|
# @see outline
|
|
94
|
-
def outline=(v)
|
|
111
|
+
def outline=(v)
|
|
112
|
+
set_run_style :validate_boolean, :outline, v
|
|
113
|
+
end
|
|
95
114
|
|
|
96
115
|
# The inline shadow property for the cell
|
|
97
116
|
# @return [Boolean]
|
|
98
117
|
attr_reader :shadow
|
|
118
|
+
|
|
99
119
|
# @see shadow
|
|
100
|
-
def shadow=(v)
|
|
120
|
+
def shadow=(v)
|
|
121
|
+
set_run_style :validate_boolean, :shadow, v
|
|
122
|
+
end
|
|
101
123
|
|
|
102
124
|
# The inline condense property for the cell
|
|
103
125
|
# @return [Boolean]
|
|
104
126
|
attr_reader :condense
|
|
127
|
+
|
|
105
128
|
# @see condense
|
|
106
|
-
def condense=(v)
|
|
129
|
+
def condense=(v)
|
|
130
|
+
set_run_style :validate_boolean, :condense, v
|
|
131
|
+
end
|
|
107
132
|
|
|
108
133
|
# The inline extend property for the cell
|
|
109
134
|
# @return [Boolean]
|
|
110
135
|
attr_reader :extend
|
|
136
|
+
|
|
111
137
|
# @see extend
|
|
112
|
-
def extend=(v)
|
|
138
|
+
def extend=(v)
|
|
139
|
+
set_run_style :validate_boolean, :extend, v
|
|
140
|
+
end
|
|
113
141
|
|
|
114
142
|
# The inline underline property for the cell.
|
|
115
143
|
# It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
|
|
116
144
|
# @return [Boolean]
|
|
117
145
|
# @return [String]
|
|
118
|
-
# @note true is for backwards
|
|
146
|
+
# @note true is for backwards compatibility and is reassigned to :single
|
|
119
147
|
attr_reader :u
|
|
148
|
+
|
|
120
149
|
# @see u
|
|
121
150
|
def u=(v)
|
|
122
|
-
v = :single if
|
|
151
|
+
v = :single if v == true || v == 1 || v == :true || v == 'true'
|
|
123
152
|
set_run_style :validate_cell_u, :u, v
|
|
124
153
|
end
|
|
125
154
|
|
|
126
155
|
# The inline color property for the cell
|
|
127
156
|
# @return [Color]
|
|
128
157
|
attr_reader :color
|
|
158
|
+
|
|
129
159
|
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
|
|
130
160
|
def color=(v)
|
|
131
|
-
@color = v.is_a?(Color) ? v : Color.new(:
|
|
161
|
+
@color = v.is_a?(Color) ? v : Color.new(rgb: v)
|
|
132
162
|
end
|
|
133
163
|
|
|
134
164
|
# The inline sz property for the cell
|
|
135
165
|
# @return [Inteter]
|
|
136
166
|
attr_reader :sz
|
|
167
|
+
|
|
137
168
|
# @see sz
|
|
138
|
-
def sz=(v)
|
|
169
|
+
def sz=(v)
|
|
170
|
+
set_run_style :validate_unsigned_int, :sz, v
|
|
171
|
+
end
|
|
139
172
|
|
|
140
173
|
# The inline vertical alignment property for the cell
|
|
141
174
|
# this must be one of [:baseline, :subscript, :superscript]
|
|
142
175
|
# @return [Symbol]
|
|
143
176
|
attr_reader :vertAlign
|
|
177
|
+
|
|
144
178
|
# @see vertAlign
|
|
145
179
|
def vertAlign=(v)
|
|
146
180
|
RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
|
|
@@ -151,6 +185,7 @@ module Axlsx
|
|
|
151
185
|
# this must be one of [:none, major, minor]
|
|
152
186
|
# @return [Symbol]
|
|
153
187
|
attr_reader :scheme
|
|
188
|
+
|
|
154
189
|
# @see scheme
|
|
155
190
|
def scheme=(v)
|
|
156
191
|
RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
|
|
@@ -162,6 +197,7 @@ module Axlsx
|
|
|
162
197
|
# @return [Array]
|
|
163
198
|
def autowidth(widtharray)
|
|
164
199
|
return if value.nil?
|
|
200
|
+
|
|
165
201
|
if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
|
|
166
202
|
first = true
|
|
167
203
|
value.to_s.split(/\r?\n/, -1).each do |line|
|
|
@@ -181,31 +217,32 @@ module Axlsx
|
|
|
181
217
|
# Utility method for setting inline style attributes
|
|
182
218
|
def set_run_style(validator, attr, value)
|
|
183
219
|
return unless INLINE_STYLES.include?(attr.to_sym)
|
|
220
|
+
|
|
184
221
|
Axlsx.send(validator, value) unless validator.nil?
|
|
185
|
-
|
|
222
|
+
instance_variable_set :"@#{attr}", value
|
|
186
223
|
end
|
|
187
224
|
|
|
188
225
|
# Serializes the RichTextRun
|
|
189
226
|
# @param [String] str
|
|
190
227
|
# @return [String]
|
|
191
|
-
def to_xml_string(str = '')
|
|
228
|
+
def to_xml_string(str = +'')
|
|
192
229
|
valid = RichTextRun::INLINE_STYLES
|
|
193
|
-
data =
|
|
194
|
-
data = data.select { |key, value| valid.include?(key)
|
|
230
|
+
data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
|
|
231
|
+
data = data.select { |key, value| !value.nil? && valid.include?(key) }
|
|
195
232
|
|
|
196
233
|
str << '<r><rPr>'
|
|
197
|
-
data.
|
|
234
|
+
data.each do |key, val|
|
|
198
235
|
case key
|
|
199
236
|
when :font_name
|
|
200
|
-
str <<
|
|
237
|
+
str << '<rFont val="' << font_name << '"/>'
|
|
201
238
|
when :color
|
|
202
|
-
str <<
|
|
239
|
+
str << val.to_xml_string
|
|
203
240
|
else
|
|
204
|
-
str <<
|
|
241
|
+
str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
|
|
205
242
|
end
|
|
206
243
|
end
|
|
207
|
-
clean_value = Axlsx
|
|
208
|
-
str <<
|
|
244
|
+
clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
|
|
245
|
+
str << '</rPr><t>' << clean_value << '</t></r>'
|
|
209
246
|
end
|
|
210
247
|
|
|
211
248
|
private
|
|
@@ -223,8 +260,9 @@ module Axlsx
|
|
|
223
260
|
# imagemagick and loading metrics for every character.
|
|
224
261
|
def font_size
|
|
225
262
|
return sz if sz
|
|
263
|
+
|
|
226
264
|
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
|
|
227
|
-
|
|
265
|
+
font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
|
|
228
266
|
end
|
|
229
267
|
|
|
230
268
|
def style
|
|
@@ -237,7 +275,7 @@ module Axlsx
|
|
|
237
275
|
|
|
238
276
|
# Converts the value to the correct XML representation (fixes issues with
|
|
239
277
|
# Numbers)
|
|
240
|
-
def xml_value
|
|
278
|
+
def xml_value(value)
|
|
241
279
|
if value == true
|
|
242
280
|
1
|
|
243
281
|
elsif value == false
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Axlsx
|
|
3
4
|
# A Row is a single row in a worksheet.
|
|
4
5
|
# @note The recommended way to manage rows and cells is to use Worksheet#add_row
|
|
@@ -6,13 +7,13 @@ module Axlsx
|
|
|
6
7
|
class Row < SimpleTypedList
|
|
7
8
|
include SerializedAttributes
|
|
8
9
|
include Accessors
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
# No support is provided for the following attributes
|
|
11
12
|
# spans
|
|
12
13
|
# thickTop
|
|
13
14
|
# thickBottom
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
# Creates a new row. New Cell objects are created based on the values, types and style options.
|
|
16
17
|
# A new cell is created for each item in the values array. style and types options are applied as follows:
|
|
17
18
|
# If the types option is defined and is a symbol it is applied to all the cells created.
|
|
18
19
|
# If the types option is an array, cell types are applied by index for each cell
|
|
@@ -24,11 +25,12 @@ module Axlsx
|
|
|
24
25
|
# @option options [Array] values
|
|
25
26
|
# @option options [Array, Symbol] types
|
|
26
27
|
# @option options [Array, Integer] style
|
|
28
|
+
# @option options [Array, Boolean] escape_formulas
|
|
27
29
|
# @option options [Float] height the row's height (in points)
|
|
28
30
|
# @option options [Integer] offset - add empty columns before values
|
|
29
31
|
# @see Row#array_to_cells
|
|
30
32
|
# @see Cell
|
|
31
|
-
def initialize(worksheet, values=[], options={})
|
|
33
|
+
def initialize(worksheet, values = [], options = {})
|
|
32
34
|
self.worksheet = worksheet
|
|
33
35
|
super(Cell, nil, values.size + options[:offset].to_i)
|
|
34
36
|
self.height = options.delete(:height)
|
|
@@ -64,7 +66,7 @@ module Axlsx
|
|
|
64
66
|
# @see Row#s
|
|
65
67
|
def s=(v)
|
|
66
68
|
Axlsx.validate_unsigned_numeric(v)
|
|
67
|
-
@custom_format = true
|
|
69
|
+
@custom_format = true
|
|
68
70
|
@s = v
|
|
69
71
|
end
|
|
70
72
|
|
|
@@ -73,7 +75,7 @@ module Axlsx
|
|
|
73
75
|
Axlsx.validate_unsigned_numeric(v)
|
|
74
76
|
@outline_level = v
|
|
75
77
|
end
|
|
76
|
-
|
|
78
|
+
|
|
77
79
|
alias :outlineLevel= :outline_level=
|
|
78
80
|
|
|
79
81
|
# The index of this row in the worksheet
|
|
@@ -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
|
|
|
@@ -104,29 +103,38 @@ module Axlsx
|
|
|
104
103
|
c
|
|
105
104
|
end
|
|
106
105
|
|
|
107
|
-
#
|
|
106
|
+
# Sets the color for every cell in this row.
|
|
108
107
|
def color=(color)
|
|
109
|
-
each_with_index do |
|
|
108
|
+
each_with_index do |cell, index|
|
|
110
109
|
cell.color = color.is_a?(Array) ? color[index] : color
|
|
111
110
|
end
|
|
112
111
|
end
|
|
113
112
|
|
|
114
|
-
#
|
|
113
|
+
# Sets the style for every cell in this row.
|
|
115
114
|
def style=(style)
|
|
116
|
-
each_with_index do |
|
|
115
|
+
each_with_index do |cell, index|
|
|
117
116
|
cell.style = style.is_a?(Array) ? style[index] : style
|
|
118
117
|
end
|
|
119
118
|
end
|
|
120
119
|
|
|
120
|
+
# Sets escape_formulas for every cell in this row. This determines whether to treat
|
|
121
|
+
# values starting with an equals sign as formulas or as literal strings.
|
|
122
|
+
# @param [Array, Boolean] value The value to set.
|
|
123
|
+
def escape_formulas=(value)
|
|
124
|
+
each_with_index do |cell, index|
|
|
125
|
+
cell.escape_formulas = value.is_a?(Array) ? value[index] : value
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
121
129
|
# @see height
|
|
122
130
|
def height=(v)
|
|
123
131
|
unless v.nil?
|
|
124
|
-
Axlsx
|
|
132
|
+
Axlsx.validate_unsigned_numeric(v)
|
|
125
133
|
@custom_height = true
|
|
126
134
|
@ht = v
|
|
127
135
|
end
|
|
128
136
|
end
|
|
129
|
-
|
|
137
|
+
|
|
130
138
|
# return cells
|
|
131
139
|
def cells
|
|
132
140
|
self
|
|
@@ -135,7 +143,10 @@ module Axlsx
|
|
|
135
143
|
private
|
|
136
144
|
|
|
137
145
|
# assigns the owning worksheet for this row
|
|
138
|
-
def worksheet=(v)
|
|
146
|
+
def worksheet=(v)
|
|
147
|
+
DataTypeValidator.validate :row_worksheet, Worksheet, v
|
|
148
|
+
@worksheet = v
|
|
149
|
+
end
|
|
139
150
|
|
|
140
151
|
# Converts values, types, and style options into cells and associates them with this row.
|
|
141
152
|
# A new cell is created for each item in the values array.
|
|
@@ -146,19 +157,19 @@ module Axlsx
|
|
|
146
157
|
# @option options [Array] values
|
|
147
158
|
# @option options [Array, Symbol] types
|
|
148
159
|
# @option options [Array, Integer] style
|
|
149
|
-
|
|
160
|
+
# @option options [Array, Boolean] escape_formulas
|
|
161
|
+
def array_to_cells(values, options = {})
|
|
150
162
|
DataTypeValidator.validate :array_to_cells, Array, values
|
|
151
163
|
types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset)
|
|
152
164
|
offset.to_i.times { |index| self[index] = Cell.new(self) } if offset
|
|
153
165
|
values.each_with_index do |value, index|
|
|
154
|
-
options[:style] = style.is_a?(Array) ? style[index] : style
|
|
166
|
+
options[:style] = (style.is_a?(Array) ? style[index] : style) || worksheet.column_info[index]&.style
|
|
155
167
|
options[:type] = types.is_a?(Array) ? types[index] : types if types
|
|
156
|
-
options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas
|
|
168
|
+
options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas unless escape_formulas.nil?
|
|
157
169
|
options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
|
|
158
170
|
|
|
159
171
|
self[index + offset.to_i] = Cell.new(self, value, options)
|
|
160
172
|
end
|
|
161
173
|
end
|
|
162
174
|
end
|
|
163
|
-
|
|
164
175
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# A collection of break objects that define row breaks (page breaks) for printing and preview
|
|
4
5
|
|
|
5
6
|
class RowBreaks < SimpleTypedList
|
|
6
|
-
|
|
7
7
|
def initialize
|
|
8
|
-
super
|
|
8
|
+
super(Break)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
# Adds a row break
|
|
@@ -13,19 +13,20 @@ module Axlsx
|
|
|
13
13
|
# max and man values are fixed.
|
|
14
14
|
# @see Break
|
|
15
15
|
def add_break(options)
|
|
16
|
-
# force feed the
|
|
17
|
-
self << Break.new(options.merge(:
|
|
16
|
+
# force feed the Excel default
|
|
17
|
+
self << Break.new(options.merge(max: 16383, man: true))
|
|
18
18
|
last
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
# <rowBreaks count="3" manualBreakCount="3">
|
|
22
22
|
# <brk id="1" max="16383" man="1"/>
|
|
23
23
|
# <brk id="7" max="16383" man="1"/>
|
|
24
24
|
# <brk id="13" max="16383" man="1"/>
|
|
25
25
|
# </rowBreaks>
|
|
26
|
-
def to_xml_string(str='')
|
|
26
|
+
def to_xml_string(str = +'')
|
|
27
27
|
return if empty?
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
|
|
29
30
|
each { |brk| brk.to_xml_string(str) }
|
|
30
31
|
str << '</rowBreaks>'
|
|
31
32
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
module Axlsx
|
|
3
4
|
# Selection options for worksheet panes.
|
|
4
5
|
#
|
|
5
6
|
# @note The recommended way to manage the selection pane options is via SheetView#add_selection
|
|
6
7
|
# @see SheetView#add_selection
|
|
7
8
|
class Selection
|
|
8
|
-
|
|
9
9
|
include Axlsx::OptionsParser
|
|
10
10
|
include Axlsx::SerializedAttributes
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ module Axlsx
|
|
|
14
14
|
# @option options [Integer] active_cell_id Active Cell Index
|
|
15
15
|
# @option options [Symbol] pane Pane
|
|
16
16
|
# @option options [String] sqref Sequence of References
|
|
17
|
-
def initialize(options={})
|
|
17
|
+
def initialize(options = {})
|
|
18
18
|
@active_cell = @active_cell_id = @pane = @sqref = nil
|
|
19
19
|
parse_options options
|
|
20
20
|
end
|
|
@@ -40,16 +40,16 @@ module Axlsx
|
|
|
40
40
|
|
|
41
41
|
# Pane
|
|
42
42
|
# The pane to which this selection belongs.
|
|
43
|
-
# Options are
|
|
43
|
+
# Options are
|
|
44
44
|
# * bottom_left: Bottom left pane, when both vertical and horizontal
|
|
45
45
|
# splits are applied. This value is also used when only
|
|
46
|
-
# a horizontal split has been applied, dividing the pane
|
|
47
|
-
# into upper and lower regions. In that case, this value
|
|
46
|
+
# a horizontal split has been applied, dividing the pane
|
|
47
|
+
# into upper and lower regions. In that case, this value
|
|
48
48
|
# specifies the bottom pane.
|
|
49
49
|
# * bottom_right: Bottom right pane, when both vertical and horizontal
|
|
50
50
|
# splits are applied.
|
|
51
51
|
# * top_left: Top left pane, when both vertical and horizontal splits
|
|
52
|
-
# are applied. This value is also used when only a horizontal
|
|
52
|
+
# are applied. This value is also used when only a horizontal
|
|
53
53
|
# split has been applied, dividing the pane into upper and lower
|
|
54
54
|
# regions. In that case, this value specifies the top pane.
|
|
55
55
|
# This value is also used when only a vertical split has
|
|
@@ -57,8 +57,8 @@ module Axlsx
|
|
|
57
57
|
# regions. In that case, this value specifies the left pane
|
|
58
58
|
# * top_right: Top right pane, when both vertical and horizontal
|
|
59
59
|
# splits are applied. This value is also used when only
|
|
60
|
-
# a vertical split has been applied, dividing the pane
|
|
61
|
-
# into right and left regions. In that case, this value
|
|
60
|
+
# a vertical split has been applied, dividing the pane
|
|
61
|
+
# into right and left regions. In that case, this value
|
|
62
62
|
# specifies the right pane.
|
|
63
63
|
# @see type
|
|
64
64
|
# @return [Symbol]
|
|
@@ -74,27 +74,33 @@ module Axlsx
|
|
|
74
74
|
|
|
75
75
|
# @see active_cell
|
|
76
76
|
def active_cell=(v)
|
|
77
|
-
cell = (v.
|
|
78
|
-
Axlsx
|
|
77
|
+
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
|
|
78
|
+
Axlsx.validate_string(cell)
|
|
79
79
|
@active_cell = cell
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# @see active_cell_id
|
|
83
|
-
def active_cell_id=(v)
|
|
83
|
+
def active_cell_id=(v)
|
|
84
|
+
Axlsx.validate_unsigned_int(v)
|
|
85
|
+
@active_cell_id = v
|
|
86
|
+
end
|
|
84
87
|
|
|
85
88
|
# @see pane
|
|
86
89
|
def pane=(v)
|
|
87
|
-
Axlsx
|
|
88
|
-
@pane = Axlsx
|
|
90
|
+
Axlsx.validate_pane_type(v)
|
|
91
|
+
@pane = Axlsx.camel(v, false)
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
# @see sqref
|
|
92
|
-
def sqref=(v)
|
|
95
|
+
def sqref=(v)
|
|
96
|
+
Axlsx.validate_string(v)
|
|
97
|
+
@sqref = v
|
|
98
|
+
end
|
|
93
99
|
|
|
94
100
|
# Serializes the data validation
|
|
95
101
|
# @param [String] str
|
|
96
102
|
# @return [String]
|
|
97
|
-
def to_xml_string(str = '')
|
|
103
|
+
def to_xml_string(str = +'')
|
|
98
104
|
serialized_tag 'selection', str
|
|
99
105
|
end
|
|
100
106
|
end
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# the SheetCalcPr object for the worksheet
|
|
4
5
|
# This object contains calculation properties for the worksheet.
|
|
5
6
|
class SheetCalcPr
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
include Axlsx::OptionsParser
|
|
8
|
+
include Axlsx::SerializedAttributes
|
|
9
|
+
include Axlsx::Accessors
|
|
10
|
+
|
|
9
11
|
# creates a new SheetCalcPr
|
|
10
12
|
# @param [Hash] options Options for this object
|
|
11
13
|
# @option [Boolean] full_calc_on_load @see full_calc_on_load
|
|
12
|
-
def initialize(options={})
|
|
14
|
+
def initialize(options = {})
|
|
13
15
|
@full_calc_on_load = true
|
|
14
16
|
parse_options options
|
|
15
17
|
end
|
|
@@ -22,8 +24,10 @@ module Axlsx
|
|
|
22
24
|
# @param [String] str the string to append this objects serialized
|
|
23
25
|
# content to.
|
|
24
26
|
# @return [String]
|
|
25
|
-
def to_xml_string(str='')
|
|
26
|
-
str <<
|
|
27
|
+
def to_xml_string(str = +'')
|
|
28
|
+
str << '<sheetCalcPr '
|
|
29
|
+
serialized_attributes(str)
|
|
30
|
+
str << '/>'
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
end
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
module Axlsx
|
|
3
4
|
# This class manages the serialization of rows for worksheets
|
|
4
5
|
class SheetData
|
|
5
|
-
|
|
6
6
|
# Creates a new SheetData object
|
|
7
7
|
# @param [Worksheet] worksheet The worksheet that owns this sheet data.
|
|
8
8
|
def initialize(worksheet)
|
|
9
9
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
|
10
|
+
|
|
10
11
|
@worksheet = worksheet
|
|
11
12
|
end
|
|
12
|
-
|
|
13
|
+
|
|
13
14
|
attr_reader :worksheet
|
|
14
15
|
|
|
15
16
|
# Serialize the sheet data
|
|
16
17
|
# @param [String] str the string this objects serializaton will be concacted to.
|
|
17
18
|
# @return [String]
|
|
18
|
-
def to_xml_string(str = '')
|
|
19
|
+
def to_xml_string(str = +'')
|
|
19
20
|
str << '<sheetData>'
|
|
20
|
-
worksheet.rows.each_with_index do |row, index|
|
|
21
|
-
row.to_xml_string(index, str)
|
|
21
|
+
worksheet.rows.each_with_index do |row, index|
|
|
22
|
+
row.to_xml_string(index, str)
|
|
22
23
|
end
|
|
23
24
|
str << '</sheetData>'
|
|
24
25
|
end
|
|
25
|
-
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# <xsd:attribute name="
|
|
7
|
-
# <xsd:attribute name="
|
|
8
|
-
# <xsd:attribute name="
|
|
9
|
-
# <xsd:attribute name="
|
|
10
|
-
# <xsd:attribute name="
|
|
11
|
-
# <xsd:attribute name="
|
|
12
|
-
# <xsd:attribute name="
|
|
13
|
-
# <xsd:attribute name="
|
|
14
|
-
|
|
3
|
+
module Axlsx
|
|
4
|
+
# Sheet formatting properties
|
|
5
|
+
# <xsd:complexType name="CT_SheetFormatPr">
|
|
6
|
+
# <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
|
|
7
|
+
# <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
|
|
8
|
+
# <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
|
|
9
|
+
# <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
|
|
10
|
+
# <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
|
|
11
|
+
# <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
|
|
12
|
+
# <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
|
|
13
|
+
# <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
|
|
14
|
+
# <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
|
|
15
|
+
# </xsd:complexType>
|
|
15
16
|
|
|
16
17
|
class SheetFormatPr
|
|
17
18
|
include Axlsx::SerializedAttributes
|
|
@@ -29,29 +30,32 @@ module Axlsx
|
|
|
29
30
|
# @option [Boolean] thick_bottom 'True' if rows have a thick bottom border by default.
|
|
30
31
|
# @option [Integer] outline_level_row Highest number of outline level for rows in this sheet. These values shall be in synch with the actual sheet outline levels.
|
|
31
32
|
# @option [Integer] outline_level_col Highest number of outline levels for columns in this sheet. These values shall be in synch with the actual sheet outline levels.
|
|
32
|
-
def initialize(options={})
|
|
33
|
+
def initialize(options = {})
|
|
33
34
|
set_defaults
|
|
34
35
|
parse_options options
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
serializable_attributes :base_col_width, :default_col_width, :default_row_height,
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
:custom_height, :zero_height, :thick_top, :thick_bottom,
|
|
40
|
+
:outline_level_row, :outline_level_col
|
|
40
41
|
|
|
41
42
|
float_attr_accessor :default_col_width, :default_row_height
|
|
42
43
|
|
|
43
44
|
boolean_attr_accessor :custom_height, :zero_height, :thick_top, :thick_bottom
|
|
44
45
|
|
|
45
|
-
unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
|
|
46
|
+
unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
|
|
46
47
|
|
|
47
48
|
# serializes this object to an xml string
|
|
48
49
|
# @param [String] str The string this objects serialization will be appended to
|
|
49
50
|
# @return [String]
|
|
50
|
-
def to_xml_string(str='')
|
|
51
|
-
str <<
|
|
51
|
+
def to_xml_string(str = +'')
|
|
52
|
+
str << '<sheetFormatPr '
|
|
53
|
+
serialized_attributes(str)
|
|
54
|
+
str << '/>'
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
private
|
|
58
|
+
|
|
55
59
|
def set_defaults
|
|
56
60
|
@base_col_width = 8
|
|
57
61
|
@default_row_height = 18
|