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
data/lib/axlsx/package.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
|
3
5
|
# xlsx document including validation and serialization.
|
@@ -31,7 +33,7 @@ module Axlsx
|
|
31
33
|
# Shortcut to specify that the workbook should use autowidth
|
32
34
|
# @see Workbook#use_autowidth
|
33
35
|
def use_autowidth=(v)
|
34
|
-
Axlsx
|
36
|
+
Axlsx.validate_boolean(v)
|
35
37
|
workbook.use_autowidth = v
|
36
38
|
end
|
37
39
|
|
@@ -44,7 +46,7 @@ module Axlsx
|
|
44
46
|
# Shortcut to specify that the workbook should use shared strings
|
45
47
|
# @see Workbook#use_shared_strings
|
46
48
|
def use_shared_strings=(v)
|
47
|
-
Axlsx
|
49
|
+
Axlsx.validate_boolean(v)
|
48
50
|
workbook.use_shared_strings = v
|
49
51
|
end
|
50
52
|
|
@@ -99,17 +101,17 @@ module Axlsx
|
|
99
101
|
# s = p.to_stream()
|
100
102
|
# File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) }
|
101
103
|
def serialize(output, options = {}, secondary_options = nil)
|
102
|
-
|
104
|
+
unless workbook.styles_applied
|
103
105
|
workbook.apply_styles
|
104
106
|
end
|
105
107
|
|
106
108
|
confirm_valid, zip_command = parse_serialize_options(options, secondary_options)
|
107
|
-
return false unless !confirm_valid ||
|
109
|
+
return false unless !confirm_valid || validate.empty?
|
108
110
|
|
109
111
|
zip_provider = if zip_command
|
110
112
|
ZipCommand.new(zip_command)
|
111
113
|
else
|
112
|
-
|
114
|
+
BufferedZipOutputStream
|
113
115
|
end
|
114
116
|
Relationship.initialize_ids_cache
|
115
117
|
zip_provider.open(output) do |zip|
|
@@ -124,15 +126,16 @@ module Axlsx
|
|
124
126
|
# @param [Boolean] confirm_valid Validate the package prior to serialization.
|
125
127
|
# @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
|
126
128
|
def to_stream(confirm_valid = false)
|
127
|
-
|
129
|
+
unless workbook.styles_applied
|
128
130
|
workbook.apply_styles
|
129
131
|
end
|
130
132
|
|
131
|
-
return false unless !confirm_valid ||
|
133
|
+
return false unless !confirm_valid || validate.empty?
|
132
134
|
|
133
135
|
Relationship.initialize_ids_cache
|
134
|
-
|
135
|
-
|
136
|
+
stream = BufferedZipOutputStream.write_buffer do |zip|
|
137
|
+
write_parts(zip)
|
138
|
+
end
|
136
139
|
stream.rewind
|
137
140
|
stream
|
138
141
|
ensure
|
@@ -142,7 +145,7 @@ module Axlsx
|
|
142
145
|
# Encrypt the package into a CFB using the password provided
|
143
146
|
# This is not ready yet
|
144
147
|
def encrypt(file_name, password)
|
145
|
-
|
148
|
+
false
|
146
149
|
# moc = MsOffCrypto.new(file_name, password)
|
147
150
|
# moc.save
|
148
151
|
end
|
@@ -156,7 +159,7 @@ module Axlsx
|
|
156
159
|
#
|
157
160
|
# If by chance you are able to create a package that does not validate it indicates that the internal
|
158
161
|
# validation is not robust enough and needs to be improved. Please report your errors to the gem author.
|
159
|
-
# @see
|
162
|
+
# @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
|
160
163
|
# @example
|
161
164
|
# # The following will output any error messages found in serialization.
|
162
165
|
# p = Axlsx::Package.new
|
@@ -213,57 +216,57 @@ module Axlsx
|
|
213
216
|
# @private
|
214
217
|
def parts
|
215
218
|
parts = [
|
216
|
-
{ :
|
217
|
-
{ :
|
218
|
-
{ :
|
219
|
-
{ :
|
220
|
-
{ :
|
219
|
+
{ entry: "xl/#{STYLES_PN}", doc: workbook.styles, schema: SML_XSD },
|
220
|
+
{ entry: CORE_PN, doc: @core, schema: CORE_XSD },
|
221
|
+
{ entry: APP_PN, doc: @app, schema: APP_XSD },
|
222
|
+
{ entry: WORKBOOK_RELS_PN, doc: workbook.relationships, schema: RELS_XSD },
|
223
|
+
{ entry: WORKBOOK_PN, doc: workbook, schema: SML_XSD }
|
221
224
|
]
|
222
225
|
|
223
226
|
workbook.drawings.each do |drawing|
|
224
|
-
parts << { :
|
225
|
-
parts << { :
|
227
|
+
parts << { entry: "xl/#{drawing.rels_pn}", doc: drawing.relationships, schema: RELS_XSD }
|
228
|
+
parts << { entry: "xl/#{drawing.pn}", doc: drawing, schema: DRAWING_XSD }
|
226
229
|
end
|
227
230
|
|
228
231
|
workbook.tables.each do |table|
|
229
|
-
parts << { :
|
232
|
+
parts << { entry: "xl/#{table.pn}", doc: table, schema: SML_XSD }
|
230
233
|
end
|
231
234
|
workbook.pivot_tables.each do |pivot_table|
|
232
235
|
cache_definition = pivot_table.cache_definition
|
233
|
-
parts << { :
|
234
|
-
parts << { :
|
235
|
-
parts << { :
|
236
|
+
parts << { entry: "xl/#{pivot_table.rels_pn}", doc: pivot_table.relationships, schema: RELS_XSD }
|
237
|
+
parts << { entry: "xl/#{pivot_table.pn}", doc: pivot_table } # , :schema => SML_XSD}
|
238
|
+
parts << { entry: "xl/#{cache_definition.pn}", doc: cache_definition } # , :schema => SML_XSD}
|
236
239
|
end
|
237
240
|
|
238
241
|
workbook.comments.each do |comment|
|
239
|
-
|
240
|
-
parts << { :
|
241
|
-
parts << { :
|
242
|
+
unless comment.empty?
|
243
|
+
parts << { entry: "xl/#{comment.pn}", doc: comment, schema: SML_XSD }
|
244
|
+
parts << { entry: "xl/#{comment.vml_drawing.pn}", doc: comment.vml_drawing, schema: nil }
|
242
245
|
end
|
243
246
|
end
|
244
247
|
|
245
248
|
workbook.charts.each do |chart|
|
246
|
-
parts << { :
|
249
|
+
parts << { entry: "xl/#{chart.pn}", doc: chart, schema: DRAWING_XSD }
|
247
250
|
end
|
248
251
|
|
249
252
|
workbook.images.each do |image|
|
250
|
-
parts << { :
|
253
|
+
parts << { entry: "xl/#{image.pn}", path: image.image_src } unless image.remote?
|
251
254
|
end
|
252
255
|
|
253
256
|
if use_shared_strings
|
254
|
-
parts << { :
|
257
|
+
parts << { entry: "xl/#{SHARED_STRINGS_PN}", doc: workbook.shared_strings, schema: SML_XSD }
|
255
258
|
end
|
256
259
|
|
257
260
|
workbook.worksheets.each do |sheet|
|
258
|
-
parts << { :
|
259
|
-
parts << { :
|
261
|
+
parts << { entry: "xl/#{sheet.rels_pn}", doc: sheet.relationships, schema: RELS_XSD }
|
262
|
+
parts << { entry: "xl/#{sheet.pn}", doc: sheet, schema: SML_XSD }
|
260
263
|
end
|
261
264
|
|
262
265
|
# Sort parts for correct MIME detection
|
263
266
|
[
|
264
|
-
{ :
|
265
|
-
{ :
|
266
|
-
*
|
267
|
+
{ entry: CONTENT_TYPES_PN, doc: content_types, schema: CONTENT_TYPES_XSD },
|
268
|
+
{ entry: RELS_PN, doc: relationships, schema: RELS_XSD },
|
269
|
+
*parts.sort_by { |part| part[:entry] }.reverse
|
267
270
|
]
|
268
271
|
end
|
269
272
|
|
@@ -289,56 +292,56 @@ module Axlsx
|
|
289
292
|
def content_types
|
290
293
|
c_types = base_content_types
|
291
294
|
workbook.drawings.each do |drawing|
|
292
|
-
c_types << Axlsx::Override.new(:
|
293
|
-
:
|
295
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{drawing.pn}",
|
296
|
+
ContentType: DRAWING_CT)
|
294
297
|
end
|
295
298
|
|
296
299
|
workbook.charts.each do |chart|
|
297
|
-
c_types << Axlsx::Override.new(:
|
298
|
-
:
|
300
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{chart.pn}",
|
301
|
+
ContentType: CHART_CT)
|
299
302
|
end
|
300
303
|
|
301
304
|
workbook.tables.each do |table|
|
302
|
-
c_types << Axlsx::Override.new(:
|
303
|
-
:
|
305
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{table.pn}",
|
306
|
+
ContentType: TABLE_CT)
|
304
307
|
end
|
305
308
|
|
306
309
|
workbook.pivot_tables.each do |pivot_table|
|
307
|
-
c_types << Axlsx::Override.new(:
|
308
|
-
:
|
309
|
-
c_types << Axlsx::Override.new(:
|
310
|
-
:
|
310
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.pn}",
|
311
|
+
ContentType: PIVOT_TABLE_CT)
|
312
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.cache_definition.pn}",
|
313
|
+
ContentType: PIVOT_TABLE_CACHE_DEFINITION_CT)
|
311
314
|
end
|
312
315
|
|
313
316
|
workbook.comments.each do |comment|
|
314
|
-
|
315
|
-
c_types << Axlsx::Override.new(:
|
316
|
-
:
|
317
|
+
unless comment.empty?
|
318
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{comment.pn}",
|
319
|
+
ContentType: COMMENT_CT)
|
317
320
|
end
|
318
321
|
end
|
319
322
|
|
320
|
-
|
321
|
-
c_types << Axlsx::Default.new(:
|
323
|
+
unless workbook.comments.empty?
|
324
|
+
c_types << Axlsx::Default.new(Extension: "vml", ContentType: VML_DRAWING_CT)
|
322
325
|
end
|
323
326
|
|
324
327
|
workbook.worksheets.each do |sheet|
|
325
|
-
c_types << Axlsx::Override.new(:
|
326
|
-
:
|
328
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{sheet.pn}",
|
329
|
+
ContentType: WORKSHEET_CT)
|
327
330
|
end
|
328
331
|
exts = workbook.images.map { |image| image.extname.downcase }
|
329
332
|
exts.uniq.each do |ext|
|
330
|
-
ct = if
|
333
|
+
ct = if JPEG_EXS.include?(ext)
|
331
334
|
JPEG_CT
|
332
|
-
elsif ext ==
|
335
|
+
elsif ext == GIF_EX
|
333
336
|
GIF_CT
|
334
|
-
elsif ext ==
|
337
|
+
elsif ext == PNG_EX
|
335
338
|
PNG_CT
|
336
339
|
end
|
337
|
-
c_types << Axlsx::Default.new(:
|
340
|
+
c_types << Axlsx::Default.new(ContentType: ct, Extension: ext)
|
338
341
|
end
|
339
342
|
if use_shared_strings
|
340
|
-
c_types << Axlsx::Override.new(:
|
341
|
-
:
|
343
|
+
c_types << Axlsx::Override.new(PartName: "/xl/#{SHARED_STRINGS_PN}",
|
344
|
+
ContentType: SHARED_STRINGS_CT)
|
342
345
|
end
|
343
346
|
c_types
|
344
347
|
end
|
@@ -347,13 +350,13 @@ module Axlsx
|
|
347
350
|
# @return [ContentType]
|
348
351
|
# @private
|
349
352
|
def base_content_types
|
350
|
-
c_types = ContentType.new
|
351
|
-
c_types << Default.new(:
|
352
|
-
c_types << Default.new(:
|
353
|
-
c_types << Override.new(:
|
354
|
-
c_types << Override.new(:
|
355
|
-
c_types << Override.new(:
|
356
|
-
c_types << Axlsx::Override.new(:
|
353
|
+
c_types = ContentType.new
|
354
|
+
c_types << Default.new(ContentType: RELS_CT, Extension: RELS_EX)
|
355
|
+
c_types << Default.new(Extension: XML_EX, ContentType: XML_CT)
|
356
|
+
c_types << Override.new(PartName: "/#{APP_PN}", ContentType: APP_CT)
|
357
|
+
c_types << Override.new(PartName: "/#{CORE_PN}", ContentType: CORE_CT)
|
358
|
+
c_types << Override.new(PartName: "/xl/#{STYLES_PN}", ContentType: STYLES_CT)
|
359
|
+
c_types << Axlsx::Override.new(PartName: "/#{WORKBOOK_PN}", ContentType: WORKBOOK_CT)
|
357
360
|
c_types.lock
|
358
361
|
c_types
|
359
362
|
end
|
@@ -376,19 +379,19 @@ module Axlsx
|
|
376
379
|
# @private
|
377
380
|
def parse_serialize_options(options, secondary_options)
|
378
381
|
if secondary_options
|
379
|
-
warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. "
|
382
|
+
warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. " \
|
380
383
|
"Use keyword args instead e.g., package.serialize(output, confirm_valid: false, zip_command: 'zip')"
|
381
384
|
end
|
382
385
|
if options.is_a?(Hash)
|
383
386
|
options.merge!(secondary_options || {})
|
384
387
|
invalid_keys = options.keys - [:confirm_valid, :zip_command]
|
385
388
|
if invalid_keys.any?
|
386
|
-
raise ArgumentError
|
389
|
+
raise ArgumentError, "Invalid keyword arguments: #{invalid_keys}"
|
387
390
|
end
|
388
391
|
|
389
392
|
[options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)]
|
390
393
|
else
|
391
|
-
warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. "
|
394
|
+
warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " \
|
392
395
|
"Use keyword args instead e.g., package.serialize(output, confirm_valid: false)"
|
393
396
|
parse_serialize_options((secondary_options || {}).merge(confirm_valid: options), nil)
|
394
397
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A relationship defines a reference between package parts.
|
3
5
|
# @note Packages automatically manage relationships.
|
@@ -41,7 +43,7 @@ module Axlsx
|
|
41
43
|
end
|
42
44
|
|
43
45
|
# The id of the relationship (eg. "rId123"). Most instances get their own unique id.
|
44
|
-
# However, some instances need to share the same id – see {#
|
46
|
+
# However, some instances need to share the same id – see {#ids_cache_key}
|
45
47
|
# for details.
|
46
48
|
# @return [String]
|
47
49
|
attr_reader :Id
|
@@ -90,9 +92,9 @@ module Axlsx
|
|
90
92
|
end
|
91
93
|
|
92
94
|
# @see Target
|
93
|
-
def Target=(v) Axlsx
|
95
|
+
def Target=(v) Axlsx.validate_string v; @Target = v end
|
94
96
|
# @see Type
|
95
|
-
def Type=(v) Axlsx
|
97
|
+
def Type=(v) Axlsx.validate_relationship_type v; @Type = v end
|
96
98
|
|
97
99
|
# @see TargetMode
|
98
100
|
def TargetMode=(v) RestrictionValidator.validate 'Relationship.TargetMode', [:External, :Internal], v; @TargetMode = v; end
|
@@ -100,10 +102,13 @@ module Axlsx
|
|
100
102
|
# serialize relationship
|
101
103
|
# @param [String] str
|
102
104
|
# @return [String]
|
103
|
-
def to_xml_string(str = '')
|
105
|
+
def to_xml_string(str = +'')
|
104
106
|
h = Axlsx.instance_values_for(self).reject { |k, _| k == "source_obj" }
|
105
107
|
str << '<Relationship '
|
106
|
-
|
108
|
+
h.each_with_index do |key_value, index|
|
109
|
+
str << ' ' unless index.zero?
|
110
|
+
str << key_value.first.to_s << '="' << Axlsx.coder.encode(key_value.last.to_s) << '"'
|
111
|
+
end
|
107
112
|
str << '/>'
|
108
113
|
end
|
109
114
|
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
|
-
require 'axlsx/rels/relationship
|
4
|
+
require 'axlsx/rels/relationship'
|
3
5
|
|
4
6
|
# Relationships are a collection of Relations that define how package parts are related.
|
5
7
|
# @note The package automatically manages releationships.
|
@@ -19,9 +21,9 @@ module Axlsx
|
|
19
21
|
# serialize relationships
|
20
22
|
# @param [String] str
|
21
23
|
# @return [String]
|
22
|
-
def to_xml_string(str = '')
|
24
|
+
def to_xml_string(str = +'')
|
23
25
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
24
|
-
str <<
|
26
|
+
str << '<Relationships xmlns="' << RELS_R << '">'
|
25
27
|
each { |rel| rel.to_xml_string(str) }
|
26
28
|
str << '</Relationships>'
|
27
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# This class details a border used in Office Open XML spreadsheet styles.
|
3
5
|
class Border
|
@@ -41,20 +43,20 @@ module Axlsx
|
|
41
43
|
attr_reader :prs
|
42
44
|
|
43
45
|
# @see diagonalUp
|
44
|
-
def diagonal_up=(v) Axlsx
|
46
|
+
def diagonal_up=(v) Axlsx.validate_boolean v; @diagonal_up = v end
|
45
47
|
alias :diagonalUp= :diagonal_up=
|
46
48
|
|
47
49
|
# @see diagonalDown
|
48
|
-
def diagonal_down=(v) Axlsx
|
50
|
+
def diagonal_down=(v) Axlsx.validate_boolean v; @diagonal_down = v end
|
49
51
|
alias :diagonalDown= :diagonal_down=
|
50
52
|
|
51
53
|
# @see outline
|
52
|
-
def outline=(v) Axlsx
|
54
|
+
def outline=(v) Axlsx.validate_boolean v; @outline = v end
|
53
55
|
|
54
56
|
# Serializes the object
|
55
57
|
# @param [String] str
|
56
58
|
# @return [String]
|
57
|
-
def to_xml_string(str = '')
|
59
|
+
def to_xml_string(str = +'')
|
58
60
|
str << '<border '
|
59
61
|
serialized_attributes str
|
60
62
|
str << '>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A border part.
|
3
5
|
class BorderPr
|
@@ -60,10 +62,10 @@ module Axlsx
|
|
60
62
|
# Serializes the object
|
61
63
|
# @param [String] str
|
62
64
|
# @return [String]
|
63
|
-
def to_xml_string(str = '')
|
64
|
-
str <<
|
65
|
+
def to_xml_string(str = +'')
|
66
|
+
str << '<' << @name.to_s << ' style="' << @style.to_s << '">'
|
65
67
|
@color.to_xml_string(str) if @color.is_a?(Color)
|
66
|
-
str <<
|
68
|
+
str << '</' << @name.to_s << '>'
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# CellAlignment stores information about the cell alignment of a style Xf Object.
|
3
5
|
# @note Using Styles#add_style is the recommended way to manage cell alignment.
|
@@ -84,40 +86,40 @@ module Axlsx
|
|
84
86
|
alias :readingOrder :reading_order
|
85
87
|
|
86
88
|
# @see horizontal
|
87
|
-
def horizontal=(v) Axlsx
|
89
|
+
def horizontal=(v) Axlsx.validate_horizontal_alignment v; @horizontal = v end
|
88
90
|
# @see vertical
|
89
|
-
def vertical=(v) Axlsx
|
91
|
+
def vertical=(v) Axlsx.validate_vertical_alignment v; @vertical = v end
|
90
92
|
# @see textRotation
|
91
|
-
def text_rotation=(v) Axlsx
|
93
|
+
def text_rotation=(v) Axlsx.validate_unsigned_int v; @text_rotation = v end
|
92
94
|
alias :textRotation= :text_rotation=
|
93
95
|
|
94
96
|
# @see wrapText
|
95
|
-
def wrap_text=(v) Axlsx
|
97
|
+
def wrap_text=(v) Axlsx.validate_boolean v; @wrap_text = v end
|
96
98
|
alias :wrapText= :wrap_text=
|
97
99
|
|
98
100
|
# @see indent
|
99
|
-
def indent=(v) Axlsx
|
101
|
+
def indent=(v) Axlsx.validate_unsigned_int v; @indent = v end
|
100
102
|
|
101
103
|
# @see relativeIndent
|
102
|
-
def relative_indent=(v) Axlsx
|
104
|
+
def relative_indent=(v) Axlsx.validate_int v; @relative_indent = v end
|
103
105
|
alias :relativeIndent= :relative_indent=
|
104
106
|
|
105
107
|
# @see justifyLastLine
|
106
|
-
def justify_last_line=(v) Axlsx
|
108
|
+
def justify_last_line=(v) Axlsx.validate_boolean v; @justify_last_line = v end
|
107
109
|
alias :justifyLastLine= :justify_last_line=
|
108
110
|
|
109
111
|
# @see shrinkToFit
|
110
|
-
def shrink_to_fit=(v) Axlsx
|
112
|
+
def shrink_to_fit=(v) Axlsx.validate_boolean v; @shrink_to_fit = v end
|
111
113
|
alias :shrinkToFit= :shrink_to_fit=
|
112
114
|
|
113
115
|
# @see readingOrder
|
114
|
-
def reading_order=(v) Axlsx
|
116
|
+
def reading_order=(v) Axlsx.validate_unsigned_int v; @reading_order = v end
|
115
117
|
alias :readingOrder= :reading_order=
|
116
118
|
|
117
119
|
# Serializes the object
|
118
120
|
# @param [String] str
|
119
121
|
# @return [String]
|
120
|
-
def to_xml_string(str = '')
|
122
|
+
def to_xml_string(str = +'')
|
121
123
|
serialized_tag('alignment', str)
|
122
124
|
end
|
123
125
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# CellProtection stores information about locking or hiding cells in spreadsheet.
|
3
5
|
# @note Using Styles#add_style is the recommended way to manage cell protection.
|
@@ -24,14 +26,14 @@ module Axlsx
|
|
24
26
|
end
|
25
27
|
|
26
28
|
# @see hidden
|
27
|
-
def hidden=(v) Axlsx
|
29
|
+
def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
|
28
30
|
# @see locked
|
29
|
-
def locked=(v) Axlsx
|
31
|
+
def locked=(v) Axlsx.validate_boolean v; @locked = v end
|
30
32
|
|
31
33
|
# Serializes the object
|
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('protection', str)
|
36
38
|
end
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# CellStyle defines named styles that reference defined formatting records and can be used in your worksheet.
|
3
5
|
# @note Using Styles#add_style is the recommended way to manage cell styling.
|
@@ -37,7 +39,7 @@ module Axlsx
|
|
37
39
|
# @return [Integer]
|
38
40
|
attr_reader :iLevel
|
39
41
|
|
40
|
-
# Determines if this named style should show in the list of styles when using
|
42
|
+
# Determines if this named style should show in the list of styles when using Excel
|
41
43
|
# @return [Boolean]
|
42
44
|
attr_reader :hidden
|
43
45
|
|
@@ -46,22 +48,22 @@ module Axlsx
|
|
46
48
|
attr_reader :customBuiltin
|
47
49
|
|
48
50
|
# @see name
|
49
|
-
def name=(v) Axlsx
|
51
|
+
def name=(v) Axlsx.validate_string v; @name = v end
|
50
52
|
# @see xfId
|
51
|
-
def xfId=(v) Axlsx
|
53
|
+
def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
|
52
54
|
# @see builtinId
|
53
|
-
def builtinId=(v) Axlsx
|
55
|
+
def builtinId=(v) Axlsx.validate_unsigned_int v; @builtinId = v end
|
54
56
|
# @see iLivel
|
55
|
-
def iLevel=(v) Axlsx
|
57
|
+
def iLevel=(v) Axlsx.validate_unsigned_int v; @iLevel = v end
|
56
58
|
# @see hidden
|
57
|
-
def hidden=(v) Axlsx
|
59
|
+
def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
|
58
60
|
# @see customBuiltin
|
59
|
-
def customBuiltin=(v) Axlsx
|
61
|
+
def customBuiltin=(v) Axlsx.validate_boolean v; @customBuiltin = v end
|
60
62
|
|
61
63
|
# Serializes the object
|
62
64
|
# @param [String] str
|
63
65
|
# @return [String]
|
64
|
-
def to_xml_string(str = '')
|
66
|
+
def to_xml_string(str = +'')
|
65
67
|
serialized_tag('cellStyle', str)
|
66
68
|
end
|
67
69
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The color class represents a color used for borders, fills an fonts
|
3
5
|
class Color
|
@@ -45,21 +47,21 @@ module Axlsx
|
|
45
47
|
attr_reader :tint
|
46
48
|
|
47
49
|
# @see auto
|
48
|
-
def auto=(v) Axlsx
|
50
|
+
def auto=(v) Axlsx.validate_boolean v; @auto = v end
|
49
51
|
|
50
52
|
# @see color
|
51
53
|
def rgb=(v)
|
52
|
-
Axlsx
|
54
|
+
Axlsx.validate_string(v)
|
53
55
|
v = v.upcase
|
54
|
-
v
|
56
|
+
v *= 3 if v.size == 2
|
55
57
|
v = v.rjust(8, 'FF')
|
56
|
-
raise ArgumentError, "Invalid color rgb value: #{v}." unless
|
58
|
+
raise ArgumentError, "Invalid color rgb value: #{v}." unless /[0-9A-F]{8}/.match?(v)
|
57
59
|
|
58
60
|
@rgb = v
|
59
61
|
end
|
60
62
|
|
61
63
|
# @see tint
|
62
|
-
def tint=(v) Axlsx
|
64
|
+
def tint=(v) Axlsx.validate_float v; @tint = v end
|
63
65
|
|
64
66
|
# This version does not support themes
|
65
67
|
# def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
|
@@ -70,8 +72,8 @@ module Axlsx
|
|
70
72
|
# Serializes the object
|
71
73
|
# @param [String] str
|
72
74
|
# @return [String]
|
73
|
-
def to_xml_string(str = '', tag_name = 'color')
|
74
|
-
serialized_tag(
|
75
|
+
def to_xml_string(str = +'', tag_name = 'color')
|
76
|
+
serialized_tag(tag_name.to_s, str)
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
data/lib/axlsx/stylesheet/dxf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
|
3
5
|
# @see Styles#add_style
|
@@ -6,7 +8,7 @@ module Axlsx
|
|
6
8
|
|
7
9
|
# The order in which the child elements is put in the XML seems to
|
8
10
|
# be important for Excel
|
9
|
-
CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
|
11
|
+
CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection].freeze
|
10
12
|
# does not support extList (ExtensionList)
|
11
13
|
|
12
14
|
# The cell alignment for this style
|
@@ -62,12 +64,12 @@ module Axlsx
|
|
62
64
|
# Serializes 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 << '<dxf>'
|
67
69
|
# Dxf elements have no attributes. All of the instance variables
|
68
70
|
# are child elements.
|
69
71
|
CHILD_ELEMENTS.each do |element|
|
70
|
-
|
72
|
+
send(element).to_xml_string(str) if send(element)
|
71
73
|
end
|
72
74
|
str << '</dxf>'
|
73
75
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The Fill is a formatting object that manages the background color, and pattern for cells.
|
3
5
|
# @note The recommended way to manage styles in your workbook is to use Styles#add_style.
|
@@ -19,7 +21,7 @@ module Axlsx
|
|
19
21
|
# Serializes the object
|
20
22
|
# @param [String] str
|
21
23
|
# @return [String]
|
22
|
-
def to_xml_string(str = '')
|
24
|
+
def to_xml_string(str = +'')
|
23
25
|
str << '<fill>'
|
24
26
|
@fill_type.to_xml_string(str)
|
25
27
|
str << '</fill>'
|