xlsxrb 0.1.17 → 0.2.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 +256 -1
- data/README.md +111 -28
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +439 -139
- data/lib/xlsxrb/chart_builder.rb +540 -193
- data/lib/xlsxrb/dsl_helpers.rb +178 -73
- data/lib/xlsxrb/elements/cell.rb +197 -130
- data/lib/xlsxrb/elements/column.rb +88 -7
- data/lib/xlsxrb/elements/coordinate_access.rb +86 -59
- data/lib/xlsxrb/elements/image.rb +18 -19
- data/lib/xlsxrb/elements/metadata.rb +2379 -0
- data/lib/xlsxrb/elements/row.rb +84 -118
- data/lib/xlsxrb/elements/styles.rb +140 -90
- data/lib/xlsxrb/elements/types.rb +164 -22
- data/lib/xlsxrb/elements/workbook.rb +122 -140
- data/lib/xlsxrb/elements/worksheet.rb +451 -226
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +16 -5
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +14 -9
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +296 -34
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +52 -50
- data/lib/xlsxrb/ooxml/styles_parser.rb +36 -5
- data/lib/xlsxrb/ooxml/utils.rb +2 -2
- data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
- data/lib/xlsxrb/ooxml/workbook_writer.rb +242 -109
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +63 -31
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +119 -56
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +33 -13
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +75 -15
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +18 -8
- data/lib/xlsxrb/ooxml/writer.rb +124 -44
- data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +112 -25
- data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
- data/lib/xlsxrb/stream_row.rb +56 -81
- data/lib/xlsxrb/stream_sheet.rb +542 -273
- data/lib/xlsxrb/stream_writer.rb +1536 -870
- data/lib/xlsxrb/style_builder.rb +667 -221
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +406 -143
- data/lib/xlsxrb/worksheet_builder.rb +1009 -900
- data/lib/xlsxrb.rb +1179 -1056
- data/sig/generated/xlsxrb/chart_builder.rbs +385 -159
- data/sig/generated/xlsxrb/dsl_helpers.rbs +81 -15
- data/sig/generated/xlsxrb/elements/cell.rbs +78 -70
- data/sig/generated/xlsxrb/elements/column.rbs +55 -3
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +35 -29
- data/sig/generated/xlsxrb/elements/image.rbs +7 -11
- data/sig/generated/xlsxrb/elements/metadata.rbs +1574 -0
- data/sig/generated/xlsxrb/elements/row.rbs +39 -42
- data/sig/generated/xlsxrb/elements/styles.rbs +66 -66
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +46 -99
- data/sig/generated/xlsxrb/elements/worksheet.rbs +121 -96
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -4
- data/sig/generated/xlsxrb/ooxml/reader.rbs +2 -2
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/utils.rbs +3 -3
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +6 -4
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +7 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +22 -13
- data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +24 -9
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
- data/sig/generated/xlsxrb/stream_row.rbs +32 -33
- data/sig/generated/xlsxrb/stream_sheet.rbs +233 -181
- data/sig/generated/xlsxrb/stream_writer.rbs +961 -667
- data/sig/generated/xlsxrb/style_builder.rbs +402 -128
- data/sig/generated/xlsxrb/workbook_builder.rbs +223 -71
- data/sig/generated/xlsxrb/worksheet_builder.rbs +579 -453
- data/sig/generated/xlsxrb.rbs +205 -144
- data/sig/rexml.rbs +8 -0
- metadata +5 -5
- data/lib/xlsxrb/utils.rb +0 -291
- data/sig/generated/xlsxrb/utils.rbs +0 -184
data/lib/xlsxrb/style_builder.rb
CHANGED
|
@@ -232,6 +232,7 @@ module Xlsxrb
|
|
|
232
232
|
sub: "subscript",
|
|
233
233
|
baseline: "baseline"
|
|
234
234
|
}.freeze
|
|
235
|
+
private_constant :COLORS, :CSS_COLORS, :BORDER_STYLES, :BORDER_INDEX_MAP
|
|
235
236
|
|
|
236
237
|
# Normalizes a color definition (CSS color name, hex code, or RGB integer) to an OpenXML hex color string.
|
|
237
238
|
#
|
|
@@ -245,7 +246,7 @@ module Xlsxrb
|
|
|
245
246
|
# @param color [String, Symbol, Integer, nil]
|
|
246
247
|
# @param alpha [Boolean] Whether to include the alpha channel ("AARRGGBB" vs "RRGGBB").
|
|
247
248
|
# @return [String, nil]
|
|
248
|
-
# @api
|
|
249
|
+
# @api private
|
|
249
250
|
#: (String | Symbol | Integer | nil color, ?alpha: bool) -> String?
|
|
250
251
|
def self.normalize_color(color, alpha: true)
|
|
251
252
|
return nil if color.nil?
|
|
@@ -299,7 +300,7 @@ module Xlsxrb
|
|
|
299
300
|
#
|
|
300
301
|
# @param style [Symbol, String, Integer, nil]
|
|
301
302
|
# @return [Symbol, nil]
|
|
302
|
-
# @api
|
|
303
|
+
# @api private
|
|
303
304
|
#: (Symbol | String | Integer | nil style) -> Symbol?
|
|
304
305
|
def self.normalize_border_style(style)
|
|
305
306
|
return nil if style.nil?
|
|
@@ -311,6 +312,23 @@ module Xlsxrb
|
|
|
311
312
|
BORDER_STYLES[sym] || BORDER_STYLES[str.downcase.to_sym]
|
|
312
313
|
end
|
|
313
314
|
|
|
315
|
+
# Normalizes a border style like normalize_border_style, raising ArgumentError for a style
|
|
316
|
+
# that is not one of the ST_BorderStyle values or their snake_case spellings.
|
|
317
|
+
#
|
|
318
|
+
# @param style [Symbol, String, Integer]
|
|
319
|
+
# @return [String]
|
|
320
|
+
# @api private
|
|
321
|
+
#: (Symbol | String | Integer style) -> String
|
|
322
|
+
def self.border_style!(style)
|
|
323
|
+
normalized = normalize_border_style(style)
|
|
324
|
+
return normalized.to_s if normalized
|
|
325
|
+
|
|
326
|
+
suggestion = DidYouMean::SpellChecker.new(dictionary: BORDER_STYLES.keys.map(&:to_s)).correct(style.to_s).first
|
|
327
|
+
message = "unknown border style: #{style.inspect}"
|
|
328
|
+
message += "; did you mean #{BORDER_STYLES[suggestion.to_sym].inspect}?" if suggestion
|
|
329
|
+
raise ArgumentError, message
|
|
330
|
+
end
|
|
331
|
+
|
|
314
332
|
# Resolves a color symbol, string, or prefix to an aRGB hex string.
|
|
315
333
|
#
|
|
316
334
|
# @param color [Symbol, String, Object, nil]
|
|
@@ -331,10 +349,6 @@ module Xlsxrb
|
|
|
331
349
|
color.to_s
|
|
332
350
|
end
|
|
333
351
|
|
|
334
|
-
def resolve_color(color)
|
|
335
|
-
self.class.resolve_color(color)
|
|
336
|
-
end
|
|
337
|
-
|
|
338
352
|
#: (?String? name) -> void
|
|
339
353
|
def initialize(name = nil)
|
|
340
354
|
@name = name
|
|
@@ -343,9 +357,77 @@ module Xlsxrb
|
|
|
343
357
|
@border_props = {}
|
|
344
358
|
@num_fmt_id = nil
|
|
345
359
|
@alignment = {}
|
|
360
|
+
@protection = {}
|
|
346
361
|
end
|
|
347
362
|
|
|
348
|
-
|
|
363
|
+
#: (String | Symbol)?
|
|
364
|
+
attr_reader :name
|
|
365
|
+
|
|
366
|
+
# @api private
|
|
367
|
+
#: Hash[Symbol, untyped]
|
|
368
|
+
attr_reader :font_props
|
|
369
|
+
|
|
370
|
+
# @api private
|
|
371
|
+
#: Hash[Symbol, untyped]
|
|
372
|
+
attr_reader :fill_props
|
|
373
|
+
|
|
374
|
+
# @api private
|
|
375
|
+
#: Hash[Symbol, untyped]
|
|
376
|
+
attr_reader :border_props
|
|
377
|
+
|
|
378
|
+
# Top-level keys accepted by #apply_options!.
|
|
379
|
+
OPTION_KEYS = %i[
|
|
380
|
+
font bold italic font_size font_name font_color underline strike vert_align superscript subscript
|
|
381
|
+
fill fill_color fill_pattern fill_gradient
|
|
382
|
+
border border_all border_left border_right border_top border_bottom
|
|
383
|
+
number_format
|
|
384
|
+
alignment align_horizontal align_vertical wrap_text text_rotation indent shrink_to_fit
|
|
385
|
+
protection locked hidden
|
|
386
|
+
].freeze
|
|
387
|
+
|
|
388
|
+
# Keys accepted inside the nested option hashes.
|
|
389
|
+
NESTED_OPTION_KEYS = {
|
|
390
|
+
font: %i[bold italic size name color underline strike vert_align superscript subscript].freeze,
|
|
391
|
+
fill: %i[color pattern fg_color bg_color].freeze,
|
|
392
|
+
fill_pattern: %i[pattern fg_color bg_color].freeze,
|
|
393
|
+
border: %i[all left right top bottom].freeze,
|
|
394
|
+
alignment: %i[horizontal vertical wrap_text text_rotation indent shrink_to_fit].freeze,
|
|
395
|
+
protection: %i[locked hidden].freeze
|
|
396
|
+
}.freeze
|
|
397
|
+
|
|
398
|
+
# Flat keys that the nested form of each group replaces; giving both is ambiguous.
|
|
399
|
+
FLAT_KEYS_BY_GROUP = {
|
|
400
|
+
font: %i[bold italic font_size font_name font_color underline strike vert_align superscript subscript].freeze,
|
|
401
|
+
fill: %i[fill_color fill_pattern].freeze,
|
|
402
|
+
border: %i[border_all border_left border_right border_top border_bottom].freeze,
|
|
403
|
+
alignment: %i[align_horizontal align_vertical wrap_text text_rotation indent shrink_to_fit].freeze,
|
|
404
|
+
protection: %i[locked hidden].freeze
|
|
405
|
+
}.freeze
|
|
406
|
+
|
|
407
|
+
# Copies the option hashes, so a copy can change without affecting the original.
|
|
408
|
+
#: (StyleBuilder source) -> void
|
|
409
|
+
def initialize_copy(source)
|
|
410
|
+
super
|
|
411
|
+
@font_props = @font_props.dup
|
|
412
|
+
@fill_props = @fill_props.dup
|
|
413
|
+
@border_props = @border_props.dup
|
|
414
|
+
@alignment = @alignment.dup
|
|
415
|
+
@protection = @protection.dup
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# Returns a copy of this style named +name+ that uses +number_format+.
|
|
419
|
+
#
|
|
420
|
+
# @param name [String] Name of the copy.
|
|
421
|
+
# @param number_format [String, Integer] Number format of the copy.
|
|
422
|
+
# @return [StyleBuilder]
|
|
423
|
+
# @api private
|
|
424
|
+
#: (String name, String | Integer number_format) -> StyleBuilder
|
|
425
|
+
def with_number_format(name, number_format)
|
|
426
|
+
copy = dup
|
|
427
|
+
copy.instance_variable_set(:@name, name)
|
|
428
|
+
copy.number_format = number_format
|
|
429
|
+
copy
|
|
430
|
+
end
|
|
349
431
|
|
|
350
432
|
# Applies option-style definitions so callers can use add_style(name, **opts)
|
|
351
433
|
# as an alternative to block-based fluent chaining.
|
|
@@ -356,37 +438,37 @@ module Xlsxrb
|
|
|
356
438
|
# @api public
|
|
357
439
|
#: (**untyped) -> self
|
|
358
440
|
def apply_options!(**opts)
|
|
441
|
+
check_options!(opts)
|
|
442
|
+
|
|
359
443
|
if opts.key?(:font)
|
|
360
444
|
font_opts = opts[:font] || {}
|
|
361
|
-
bold
|
|
362
|
-
italic
|
|
363
|
-
|
|
364
|
-
font_name
|
|
365
|
-
font_color
|
|
366
|
-
underline
|
|
367
|
-
strike
|
|
368
|
-
vert_align
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
subscript(font_opts[:subscript]) if font_opts.key?(:subscript)
|
|
445
|
+
self.bold = font_opts[:bold] if font_opts.key?(:bold)
|
|
446
|
+
self.italic = font_opts[:italic] if font_opts.key?(:italic)
|
|
447
|
+
self.font_size = font_opts[:size] if font_opts.key?(:size)
|
|
448
|
+
self.font_name = font_opts[:name] if font_opts.key?(:name)
|
|
449
|
+
self.font_color = font_opts[:color] if font_opts.key?(:color)
|
|
450
|
+
self.underline = font_opts[:underline] if font_opts.key?(:underline)
|
|
451
|
+
self.strike = font_opts[:strike] if font_opts.key?(:strike)
|
|
452
|
+
self.vert_align = font_opts[:vert_align] if font_opts.key?(:vert_align)
|
|
453
|
+
self.superscript = font_opts[:superscript] if font_opts.key?(:superscript)
|
|
454
|
+
self.subscript = font_opts[:subscript] if font_opts.key?(:subscript)
|
|
372
455
|
else
|
|
373
|
-
bold
|
|
374
|
-
italic
|
|
375
|
-
|
|
376
|
-
font_name
|
|
377
|
-
font_color
|
|
378
|
-
underline
|
|
379
|
-
strike
|
|
380
|
-
vert_align
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
subscript(opts[:subscript]) if opts.key?(:subscript)
|
|
456
|
+
self.bold = opts[:bold] if opts.key?(:bold)
|
|
457
|
+
self.italic = opts[:italic] if opts.key?(:italic)
|
|
458
|
+
self.font_size = opts[:font_size] if opts.key?(:font_size)
|
|
459
|
+
self.font_name = opts[:font_name] if opts.key?(:font_name)
|
|
460
|
+
self.font_color = opts[:font_color] if opts.key?(:font_color)
|
|
461
|
+
self.underline = opts[:underline] if opts.key?(:underline)
|
|
462
|
+
self.strike = opts[:strike] if opts.key?(:strike)
|
|
463
|
+
self.vert_align = opts[:vert_align] if opts.key?(:vert_align)
|
|
464
|
+
self.superscript = opts[:superscript] if opts.key?(:superscript)
|
|
465
|
+
self.subscript = opts[:subscript] if opts.key?(:subscript)
|
|
384
466
|
end
|
|
385
467
|
|
|
386
468
|
if opts.key?(:fill)
|
|
387
469
|
fill_opts = opts[:fill] || {}
|
|
388
470
|
if fill_opts.key?(:color)
|
|
389
|
-
fill_color
|
|
471
|
+
self.fill_color = fill_opts[:color]
|
|
390
472
|
else
|
|
391
473
|
fill_pattern(
|
|
392
474
|
fill_opts[:pattern] || "solid",
|
|
@@ -395,7 +477,7 @@ module Xlsxrb
|
|
|
395
477
|
)
|
|
396
478
|
end
|
|
397
479
|
else
|
|
398
|
-
fill_color
|
|
480
|
+
self.fill_color = opts[:fill_color] if opts.key?(:fill_color)
|
|
399
481
|
if opts.key?(:fill_pattern)
|
|
400
482
|
pattern = opts[:fill_pattern] || {}
|
|
401
483
|
fill_pattern(
|
|
@@ -422,23 +504,32 @@ module Xlsxrb
|
|
|
422
504
|
border_bottom(**opts[:border_bottom]) if opts.key?(:border_bottom) && opts[:border_bottom]
|
|
423
505
|
end
|
|
424
506
|
|
|
425
|
-
number_format
|
|
507
|
+
self.number_format = opts[:number_format] if opts.key?(:number_format)
|
|
426
508
|
|
|
427
509
|
if opts.key?(:alignment)
|
|
428
510
|
align_opts = opts[:alignment] || {}
|
|
429
|
-
align_horizontal
|
|
430
|
-
align_vertical
|
|
431
|
-
wrap_text
|
|
432
|
-
text_rotation
|
|
433
|
-
indent
|
|
434
|
-
shrink_to_fit
|
|
511
|
+
self.align_horizontal = align_opts[:horizontal] if align_opts.key?(:horizontal)
|
|
512
|
+
self.align_vertical = align_opts[:vertical] if align_opts.key?(:vertical)
|
|
513
|
+
self.wrap_text = align_opts[:wrap_text] if align_opts.key?(:wrap_text)
|
|
514
|
+
self.text_rotation = align_opts[:text_rotation] if align_opts.key?(:text_rotation)
|
|
515
|
+
self.indent = align_opts[:indent] if align_opts.key?(:indent)
|
|
516
|
+
self.shrink_to_fit = align_opts[:shrink_to_fit] if align_opts.key?(:shrink_to_fit)
|
|
517
|
+
else
|
|
518
|
+
self.align_horizontal = opts[:align_horizontal] if opts.key?(:align_horizontal)
|
|
519
|
+
self.align_vertical = opts[:align_vertical] if opts.key?(:align_vertical)
|
|
520
|
+
self.wrap_text = opts[:wrap_text] if opts.key?(:wrap_text)
|
|
521
|
+
self.text_rotation = opts[:text_rotation] if opts.key?(:text_rotation)
|
|
522
|
+
self.indent = opts[:indent] if opts.key?(:indent)
|
|
523
|
+
self.shrink_to_fit = opts[:shrink_to_fit] if opts.key?(:shrink_to_fit)
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
if opts.key?(:protection)
|
|
527
|
+
prot_opts = opts[:protection] || {}
|
|
528
|
+
self.locked = prot_opts[:locked] if prot_opts.key?(:locked)
|
|
529
|
+
self.hidden = prot_opts[:hidden] if prot_opts.key?(:hidden)
|
|
435
530
|
else
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
wrap_text(opts[:wrap_text]) if opts.key?(:wrap_text)
|
|
439
|
-
text_rotation(opts[:text_rotation]) if opts.key?(:text_rotation)
|
|
440
|
-
indent(opts[:indent]) if opts.key?(:indent)
|
|
441
|
-
shrink_to_fit(opts[:shrink_to_fit]) if opts.key?(:shrink_to_fit)
|
|
531
|
+
self.locked = opts[:locked] if opts.key?(:locked)
|
|
532
|
+
self.hidden = opts[:hidden] if opts.key?(:hidden)
|
|
442
533
|
end
|
|
443
534
|
|
|
444
535
|
self
|
|
@@ -446,83 +537,140 @@ module Xlsxrb
|
|
|
446
537
|
|
|
447
538
|
# --- Font Properties ---
|
|
448
539
|
|
|
449
|
-
# Configures multiple font properties at once.
|
|
540
|
+
# Configures multiple font properties at once or returns font properties.
|
|
450
541
|
# @param opts [Hash] The font properties.
|
|
451
|
-
# @return [
|
|
542
|
+
# @return [Hash, void]
|
|
452
543
|
# @api public
|
|
453
|
-
#: (
|
|
544
|
+
#: () -> Hash[Symbol, untyped]
|
|
545
|
+
#: (**untyped) -> void
|
|
454
546
|
def font(**opts)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
self
|
|
547
|
+
return @font_props if opts.empty?
|
|
548
|
+
|
|
549
|
+
self.bold = opts[:bold] if opts.key?(:bold)
|
|
550
|
+
self.italic = opts[:italic] if opts.key?(:italic)
|
|
551
|
+
self.font_size = opts[:size] if opts.key?(:size)
|
|
552
|
+
self.font_name = opts[:name] if opts.key?(:name)
|
|
553
|
+
self.font_color = opts[:color] if opts.key?(:color)
|
|
554
|
+
self.underline = opts[:underline] if opts.key?(:underline)
|
|
555
|
+
self.strike = opts[:strike] if opts.key?(:strike)
|
|
556
|
+
self.vert_align = opts[:vert_align] if opts.key?(:vert_align)
|
|
557
|
+
self.superscript = opts[:superscript] if opts.key?(:superscript)
|
|
558
|
+
self.subscript = opts[:subscript] if opts.key?(:subscript)
|
|
559
|
+
nil
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
# Sets font options.
|
|
563
|
+
# @param opts [Hash]
|
|
564
|
+
# @return [Hash]
|
|
565
|
+
# @api public
|
|
566
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
567
|
+
def font=(opts)
|
|
568
|
+
font(**opts)
|
|
569
|
+
opts
|
|
467
570
|
end
|
|
468
571
|
|
|
469
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
|
470
572
|
# Sets the font to bold.
|
|
471
|
-
# @param value [Boolean]
|
|
472
|
-
# @return [
|
|
573
|
+
# @param value [Boolean]
|
|
574
|
+
# @return [Boolean]
|
|
473
575
|
# @api public
|
|
474
|
-
#: (
|
|
475
|
-
def bold(value
|
|
476
|
-
@font_props[:bold] = value
|
|
477
|
-
|
|
576
|
+
#: (bool value) -> bool
|
|
577
|
+
def bold=(value)
|
|
578
|
+
@font_props[:bold] = value ? true : false
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
# Returns whether bold is enabled.
|
|
582
|
+
# @return [Boolean]
|
|
583
|
+
# @api public
|
|
584
|
+
#: () -> bool
|
|
585
|
+
def bold?
|
|
586
|
+
@font_props[:bold] ? true : false
|
|
478
587
|
end
|
|
479
588
|
|
|
480
589
|
# Sets the font to italic.
|
|
481
|
-
# @param value [Boolean]
|
|
482
|
-
# @return [
|
|
590
|
+
# @param value [Boolean]
|
|
591
|
+
# @return [Boolean]
|
|
483
592
|
# @api public
|
|
484
|
-
#: (
|
|
485
|
-
def italic(value
|
|
486
|
-
@font_props[:italic] = value
|
|
487
|
-
self
|
|
593
|
+
#: (bool value) -> bool
|
|
594
|
+
def italic=(value)
|
|
595
|
+
@font_props[:italic] = value ? true : false
|
|
488
596
|
end
|
|
489
597
|
|
|
490
|
-
#
|
|
491
|
-
# @
|
|
492
|
-
# @return [self]
|
|
598
|
+
# Returns whether italic is enabled.
|
|
599
|
+
# @return [Boolean]
|
|
493
600
|
# @api public
|
|
494
|
-
#: (
|
|
495
|
-
def
|
|
496
|
-
@font_props[:
|
|
497
|
-
|
|
601
|
+
#: () -> bool
|
|
602
|
+
def italic?
|
|
603
|
+
@font_props[:italic] ? true : false
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
# Gets the font size in points.
|
|
607
|
+
# @return [Integer, Float, nil]
|
|
608
|
+
# @api public
|
|
609
|
+
#: () -> (Integer | Float | nil)
|
|
610
|
+
def font_size
|
|
611
|
+
@font_props[:size]
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
# Sets the font size in points.
|
|
615
|
+
# @param size_value [Integer, Float] The size in points (supports fractional sizes such as 10.5).
|
|
616
|
+
# @return [Integer, Float]
|
|
617
|
+
# @api public
|
|
618
|
+
#: (Numeric size_value) -> Numeric
|
|
619
|
+
def font_size=(size_value)
|
|
620
|
+
val = size_value.is_a?(Float) && (size_value % 1).zero? ? size_value.to_i : size_value
|
|
621
|
+
@font_props[:size] = val
|
|
622
|
+
size_value
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
# Gets the font name.
|
|
626
|
+
# @return [String, nil]
|
|
627
|
+
# @api public
|
|
628
|
+
#: () -> String?
|
|
629
|
+
def font_name
|
|
630
|
+
@font_props[:name]
|
|
498
631
|
end
|
|
499
632
|
|
|
500
633
|
# Sets the font name.
|
|
501
|
-
# @param name [String]
|
|
502
|
-
# @return [
|
|
634
|
+
# @param name [String]
|
|
635
|
+
# @return [String]
|
|
503
636
|
# @api public
|
|
504
|
-
#: (String) ->
|
|
505
|
-
def font_name(name)
|
|
637
|
+
#: (String name) -> String
|
|
638
|
+
def font_name=(name)
|
|
506
639
|
@font_props[:name] = name
|
|
507
|
-
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
# Gets the font color.
|
|
643
|
+
# @return [String, nil]
|
|
644
|
+
# @api public
|
|
645
|
+
#: () -> String?
|
|
646
|
+
def font_color
|
|
647
|
+
@font_props[:color]
|
|
508
648
|
end
|
|
509
649
|
|
|
510
650
|
# Sets the font color.
|
|
511
|
-
# @param color [String, Symbol]
|
|
512
|
-
# @return [
|
|
651
|
+
# @param color [String, Symbol]
|
|
652
|
+
# @return [String, Symbol]
|
|
513
653
|
# @api public
|
|
514
|
-
#: (String | Symbol) ->
|
|
515
|
-
def font_color(color)
|
|
654
|
+
#: (String | Symbol color) -> (String | Symbol)
|
|
655
|
+
def font_color=(color)
|
|
516
656
|
@font_props[:color] = resolve_color(color)
|
|
517
|
-
|
|
657
|
+
color
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
# Gets the font underline style.
|
|
661
|
+
# @return [String, Symbol, Boolean, nil]
|
|
662
|
+
# @api public
|
|
663
|
+
#: () -> (String | Symbol | bool | nil)
|
|
664
|
+
def underline
|
|
665
|
+
@font_props[:underline]
|
|
518
666
|
end
|
|
519
667
|
|
|
520
668
|
# Sets the font underline style.
|
|
521
|
-
# @param val [String, Symbol, Boolean]
|
|
522
|
-
# @return [
|
|
669
|
+
# @param val [String, Symbol, Boolean]
|
|
670
|
+
# @return [String, Symbol, Boolean]
|
|
523
671
|
# @api public
|
|
524
|
-
#: (
|
|
525
|
-
def underline(val
|
|
672
|
+
#: (String | Symbol | bool val) -> (String | Symbol | bool)
|
|
673
|
+
def underline=(val)
|
|
526
674
|
mapped = if [true, "single"].include?(val)
|
|
527
675
|
"single"
|
|
528
676
|
elsif val == false
|
|
@@ -531,183 +679,288 @@ module Xlsxrb
|
|
|
531
679
|
UNDERLINE_MAP[val.to_sym] || val.to_s
|
|
532
680
|
end
|
|
533
681
|
@font_props[:underline] = mapped
|
|
534
|
-
|
|
682
|
+
val
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
# Returns whether underline is enabled.
|
|
686
|
+
# @return [Boolean]
|
|
687
|
+
# @api public
|
|
688
|
+
#: () -> bool
|
|
689
|
+
def underline?
|
|
690
|
+
!@font_props[:underline].nil? && @font_props[:underline] != false
|
|
535
691
|
end
|
|
536
692
|
|
|
537
693
|
# Sets the font strikethrough.
|
|
538
|
-
# @param value [Boolean]
|
|
539
|
-
# @return [
|
|
694
|
+
# @param value [Boolean]
|
|
695
|
+
# @return [Boolean]
|
|
540
696
|
# @api public
|
|
541
|
-
#: (
|
|
542
|
-
def strike(value
|
|
543
|
-
@font_props[:strike] = value
|
|
544
|
-
|
|
697
|
+
#: (bool value) -> bool
|
|
698
|
+
def strike=(value)
|
|
699
|
+
@font_props[:strike] = value ? true : false
|
|
700
|
+
end
|
|
701
|
+
|
|
702
|
+
# Returns whether strikethrough is enabled.
|
|
703
|
+
# @return [Boolean]
|
|
704
|
+
# @api public
|
|
705
|
+
#: () -> bool
|
|
706
|
+
def strike?
|
|
707
|
+
@font_props[:strike] ? true : false
|
|
708
|
+
end
|
|
709
|
+
|
|
710
|
+
# Gets the vertical alignment of the font.
|
|
711
|
+
# @return [String, nil]
|
|
712
|
+
# @api public
|
|
713
|
+
#: () -> String?
|
|
714
|
+
def vert_align
|
|
715
|
+
@font_props[:vert_align]
|
|
545
716
|
end
|
|
546
717
|
|
|
547
718
|
# Sets the vertical alignment of the font.
|
|
548
|
-
# @param
|
|
549
|
-
# @return [
|
|
719
|
+
# @param val [String, Symbol]
|
|
720
|
+
# @return [Object]
|
|
550
721
|
# @api public
|
|
551
|
-
#: (
|
|
552
|
-
def vert_align(
|
|
553
|
-
mapped = VERT_ALIGN_MAP[
|
|
722
|
+
#: (untyped val) -> untyped
|
|
723
|
+
def vert_align=(val)
|
|
724
|
+
mapped = VERT_ALIGN_MAP[val.to_sym] || val.to_s
|
|
554
725
|
@font_props[:vert_align] = mapped
|
|
555
|
-
|
|
726
|
+
val
|
|
556
727
|
end
|
|
557
728
|
|
|
558
729
|
# Sets the font to superscript.
|
|
559
|
-
# @param
|
|
560
|
-
# @return [
|
|
730
|
+
# @param val [Boolean]
|
|
731
|
+
# @return [Boolean]
|
|
561
732
|
# @api public
|
|
562
|
-
#: (
|
|
563
|
-
def superscript(
|
|
564
|
-
@font_props[:vert_align] =
|
|
565
|
-
|
|
733
|
+
#: (untyped val) -> untyped
|
|
734
|
+
def superscript=(val)
|
|
735
|
+
@font_props[:vert_align] = val ? "superscript" : "baseline"
|
|
736
|
+
val
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
# Returns whether superscript is enabled.
|
|
740
|
+
# @return [Boolean]
|
|
741
|
+
# @api public
|
|
742
|
+
#: () -> bool
|
|
743
|
+
def superscript?
|
|
744
|
+
@font_props[:vert_align] == "superscript"
|
|
566
745
|
end
|
|
567
746
|
|
|
568
747
|
# Sets the font to subscript.
|
|
569
|
-
# @param
|
|
570
|
-
# @return [
|
|
748
|
+
# @param val [Boolean]
|
|
749
|
+
# @return [Boolean]
|
|
571
750
|
# @api public
|
|
572
|
-
#: (
|
|
573
|
-
def subscript(
|
|
574
|
-
@font_props[:vert_align] =
|
|
575
|
-
|
|
751
|
+
#: (untyped val) -> untyped
|
|
752
|
+
def subscript=(val)
|
|
753
|
+
@font_props[:vert_align] = val ? "subscript" : "baseline"
|
|
754
|
+
val
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
# Returns whether subscript is enabled.
|
|
758
|
+
# @return [Boolean]
|
|
759
|
+
# @api public
|
|
760
|
+
#: () -> bool
|
|
761
|
+
def subscript?
|
|
762
|
+
@font_props[:vert_align] == "subscript"
|
|
576
763
|
end
|
|
577
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
578
764
|
|
|
579
765
|
# --- Fill Properties ---
|
|
580
766
|
|
|
581
|
-
# Sets the fill pattern.
|
|
582
|
-
# @param pattern [String, Symbol] The pattern type.
|
|
767
|
+
# Sets or gets the fill pattern.
|
|
768
|
+
# @param pattern [String, Symbol, nil] The pattern type.
|
|
583
769
|
# @param fg_color [String, Symbol, nil] The foreground color.
|
|
584
770
|
# @param bg_color [String, Symbol, nil] The background color.
|
|
585
|
-
# @return [
|
|
771
|
+
# @return [String, Symbol, void, nil]
|
|
586
772
|
# @api public
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
#: (String | Symbol pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> self
|
|
594
|
-
def fill_pattern(pattern, fg_color: nil, bg_color: nil)
|
|
595
|
-
@fill_props[:pattern] = pattern
|
|
773
|
+
#: () -> (String | Symbol | untyped)
|
|
774
|
+
#: (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
775
|
+
def fill_pattern(pattern = nil, fg_color: nil, bg_color: nil)
|
|
776
|
+
return @fill_props[:pattern] if pattern.nil? && fg_color.nil? && bg_color.nil?
|
|
777
|
+
|
|
778
|
+
@fill_props[:pattern] = pattern if pattern
|
|
596
779
|
@fill_props[:fg_color] = fg_color if fg_color
|
|
597
780
|
@fill_props[:bg_color] = bg_color if bg_color
|
|
598
|
-
|
|
781
|
+
nil
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
# Sets the fill pattern.
|
|
785
|
+
# @param pattern [String, Symbol, Hash]
|
|
786
|
+
# @return [Object]
|
|
787
|
+
# @api public
|
|
788
|
+
#: (untyped pattern) -> untyped
|
|
789
|
+
def fill_pattern=(pattern)
|
|
790
|
+
if pattern.is_a?(Hash)
|
|
791
|
+
fill_pattern(pattern[:pattern] || "solid", fg_color: pattern[:fg_color], bg_color: pattern[:bg_color])
|
|
792
|
+
else
|
|
793
|
+
@fill_props[:pattern] = pattern
|
|
794
|
+
end
|
|
795
|
+
pattern
|
|
796
|
+
end
|
|
797
|
+
|
|
798
|
+
# Gets a solid fill color.
|
|
799
|
+
# @return [String, nil]
|
|
800
|
+
# @api public
|
|
801
|
+
#: () -> String?
|
|
802
|
+
def fill_color
|
|
803
|
+
@fill_props[:fg_color]
|
|
599
804
|
end
|
|
600
805
|
|
|
601
806
|
# Sets a solid fill color.
|
|
602
|
-
# @param color [String, Symbol]
|
|
603
|
-
# @return [
|
|
807
|
+
# @param color [String, Symbol]
|
|
808
|
+
# @return [String, Symbol]
|
|
604
809
|
# @api public
|
|
605
|
-
#: (String | Symbol) ->
|
|
606
|
-
def fill_color(color)
|
|
810
|
+
#: (String | Symbol color) -> (String | Symbol)
|
|
811
|
+
def fill_color=(color)
|
|
607
812
|
@fill_props[:pattern] = "solid"
|
|
608
813
|
@fill_props[:fg_color] = resolve_color(color)
|
|
609
|
-
|
|
814
|
+
color
|
|
610
815
|
end
|
|
611
816
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
817
|
+
# Configures fill properties or returns current fill properties.
|
|
818
|
+
# @param pattern [String, Symbol, nil]
|
|
819
|
+
# @param fg_color [String, Symbol, nil]
|
|
820
|
+
# @param bg_color [String, Symbol, nil]
|
|
821
|
+
# @return [Hash, void]
|
|
822
|
+
# @api public
|
|
823
|
+
#: () -> Hash[Symbol, untyped]
|
|
824
|
+
#: (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> void
|
|
825
|
+
def fill(pattern: nil, fg_color: nil, bg_color: nil)
|
|
826
|
+
return @fill_props if pattern.nil? && fg_color.nil? && bg_color.nil?
|
|
827
|
+
|
|
828
|
+
pat = pattern || "solid"
|
|
829
|
+
fill_pattern(pat, fg_color: resolve_color(fg_color), bg_color: resolve_color(bg_color))
|
|
830
|
+
nil
|
|
615
831
|
end
|
|
616
832
|
|
|
617
|
-
# Sets
|
|
618
|
-
# @param
|
|
833
|
+
# Sets fill options.
|
|
834
|
+
# @param opts [Hash, Object]
|
|
835
|
+
# @return [Object]
|
|
836
|
+
# @api public
|
|
837
|
+
#: (untyped opts) -> untyped
|
|
838
|
+
def fill=(opts)
|
|
839
|
+
if opts.is_a?(Hash)
|
|
840
|
+
fill(**opts)
|
|
841
|
+
else
|
|
842
|
+
fill(pattern: opts)
|
|
843
|
+
end
|
|
844
|
+
opts
|
|
845
|
+
end
|
|
846
|
+
|
|
847
|
+
# Sets or gets a gradient fill.
|
|
848
|
+
# @param type [String, nil] The gradient type.
|
|
619
849
|
# @param degree [Numeric, nil] The degree.
|
|
620
850
|
# @param stops [Array] The gradient stops.
|
|
621
|
-
# @return [
|
|
851
|
+
# @return [Hash, void, nil]
|
|
622
852
|
# @api public
|
|
623
|
-
#: (
|
|
624
|
-
|
|
853
|
+
#: () -> Hash[Symbol, untyped]?
|
|
854
|
+
#: (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> void
|
|
855
|
+
def fill_gradient(type: nil, degree: nil, stops: [])
|
|
856
|
+
return @fill_props[:gradient] if type.nil? && degree.nil? && stops.empty?
|
|
857
|
+
|
|
625
858
|
@fill_props[:gradient] = {
|
|
626
859
|
type: type,
|
|
627
860
|
degree: degree,
|
|
628
861
|
stops: stops
|
|
629
862
|
}.compact
|
|
630
|
-
|
|
863
|
+
nil
|
|
631
864
|
end
|
|
632
865
|
|
|
633
866
|
# --- Border Properties ---
|
|
634
867
|
|
|
635
|
-
# Configures multiple border properties.
|
|
636
|
-
#
|
|
637
|
-
# @
|
|
868
|
+
# Configures multiple border properties or returns current border properties.
|
|
869
|
+
#
|
|
870
|
+
# @param all [Hash, nil] Border options for all sides.
|
|
871
|
+
# @param left [Hash, nil] Options for left border.
|
|
872
|
+
# @param right [Hash, nil] Options for right border.
|
|
873
|
+
# @param top [Hash, nil] Options for top border.
|
|
874
|
+
# @param bottom [Hash, nil] Options for bottom border.
|
|
875
|
+
# @param diagonal [Hash, nil] Options for diagonal border.
|
|
876
|
+
# @return [Hash, void]
|
|
638
877
|
# @api public
|
|
639
|
-
#: (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
878
|
+
#: () -> Hash[Symbol, untyped]
|
|
879
|
+
#: (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> void
|
|
880
|
+
def border(all: nil, left: nil, right: nil, top: nil, bottom: nil, diagonal: nil)
|
|
881
|
+
return @border_props if all.nil? && left.nil? && right.nil? && top.nil? && bottom.nil? && diagonal.nil?
|
|
882
|
+
|
|
883
|
+
border_all(**all) if all
|
|
884
|
+
border_left(**left) if left
|
|
885
|
+
border_right(**right) if right
|
|
886
|
+
border_top(**top) if top
|
|
887
|
+
border_bottom(**bottom) if bottom
|
|
888
|
+
border_diagonal(**diagonal) if diagonal
|
|
889
|
+
nil
|
|
890
|
+
end
|
|
891
|
+
|
|
892
|
+
# Sets border options.
|
|
893
|
+
# @param opts [Hash]
|
|
894
|
+
# @return [Hash]
|
|
895
|
+
# @api public
|
|
896
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
897
|
+
def border=(opts)
|
|
898
|
+
border(**opts)
|
|
899
|
+
opts
|
|
647
900
|
end
|
|
648
901
|
|
|
649
902
|
# Sets all borders.
|
|
650
903
|
# @param style [String, Symbol, Integer] The border style.
|
|
651
904
|
# @param color [String, Symbol, nil] The color.
|
|
652
|
-
# @return [
|
|
905
|
+
# @return [void]
|
|
653
906
|
# @api public
|
|
654
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) ->
|
|
907
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
655
908
|
def border_all(style: "thin", color: nil)
|
|
656
|
-
norm_style = self.class.
|
|
909
|
+
norm_style = self.class.border_style!(style)
|
|
657
910
|
color_opt = color ? { color: resolve_color(color) } : {}
|
|
658
911
|
@border_props[:left] = { style: norm_style, **color_opt }
|
|
659
912
|
@border_props[:right] = { style: norm_style, **color_opt }
|
|
660
913
|
@border_props[:top] = { style: norm_style, **color_opt }
|
|
661
914
|
@border_props[:bottom] = { style: norm_style, **color_opt }
|
|
662
|
-
|
|
915
|
+
nil
|
|
663
916
|
end
|
|
664
917
|
|
|
665
918
|
# Sets the left border.
|
|
666
919
|
# @param style [String, Symbol, Integer] The border style.
|
|
667
920
|
# @param color [String, Symbol, nil] The color.
|
|
668
|
-
# @return [
|
|
921
|
+
# @return [void]
|
|
669
922
|
# @api public
|
|
670
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) ->
|
|
923
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
671
924
|
def border_left(style: "thin", color: nil)
|
|
672
|
-
norm_style = self.class.
|
|
925
|
+
norm_style = self.class.border_style!(style)
|
|
673
926
|
@border_props[:left] = { style: norm_style, color: resolve_color(color) }.compact
|
|
674
|
-
|
|
927
|
+
nil
|
|
675
928
|
end
|
|
676
929
|
|
|
677
930
|
# Sets the right border.
|
|
678
931
|
# @param style [String, Symbol, Integer] The border style.
|
|
679
932
|
# @param color [String, Symbol, nil] The color.
|
|
680
|
-
# @return [
|
|
933
|
+
# @return [void]
|
|
681
934
|
# @api public
|
|
682
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) ->
|
|
935
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
683
936
|
def border_right(style: "thin", color: nil)
|
|
684
|
-
norm_style = self.class.
|
|
937
|
+
norm_style = self.class.border_style!(style)
|
|
685
938
|
@border_props[:right] = { style: norm_style, color: resolve_color(color) }.compact
|
|
686
|
-
|
|
939
|
+
nil
|
|
687
940
|
end
|
|
688
941
|
|
|
689
942
|
# Sets the top border.
|
|
690
943
|
# @param style [String, Symbol, Integer] The border style.
|
|
691
944
|
# @param color [String, Symbol, nil] The color.
|
|
692
|
-
# @return [
|
|
945
|
+
# @return [void]
|
|
693
946
|
# @api public
|
|
694
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) ->
|
|
947
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
695
948
|
def border_top(style: "thin", color: nil)
|
|
696
|
-
norm_style = self.class.
|
|
949
|
+
norm_style = self.class.border_style!(style)
|
|
697
950
|
@border_props[:top] = { style: norm_style, color: resolve_color(color) }.compact
|
|
698
|
-
|
|
951
|
+
nil
|
|
699
952
|
end
|
|
700
953
|
|
|
701
954
|
# Sets the bottom border.
|
|
702
955
|
# @param style [String, Symbol, Integer] The border style.
|
|
703
956
|
# @param color [String, Symbol, nil] The color.
|
|
704
|
-
# @return [
|
|
957
|
+
# @return [void]
|
|
705
958
|
# @api public
|
|
706
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) ->
|
|
959
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil) -> void
|
|
707
960
|
def border_bottom(style: "thin", color: nil)
|
|
708
|
-
norm_style = self.class.
|
|
961
|
+
norm_style = self.class.border_style!(style)
|
|
709
962
|
@border_props[:bottom] = { style: norm_style, color: resolve_color(color) }.compact
|
|
710
|
-
|
|
963
|
+
nil
|
|
711
964
|
end
|
|
712
965
|
|
|
713
966
|
# rubocop:disable Naming/MethodParameterName
|
|
@@ -716,94 +969,250 @@ module Xlsxrb
|
|
|
716
969
|
# @param color [String, Symbol, nil] The color.
|
|
717
970
|
# @param up [Boolean] Diagonal up.
|
|
718
971
|
# @param down [Boolean] Diagonal down.
|
|
719
|
-
# @return [
|
|
972
|
+
# @return [void]
|
|
720
973
|
# @api public
|
|
721
|
-
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) ->
|
|
974
|
+
#: (?style: String | Symbol | Integer, ?color: String | Symbol | nil, ?up: bool, ?down: bool) -> void
|
|
722
975
|
def border_diagonal(style: "thin", color: nil, up: false, down: false)
|
|
723
|
-
norm_style = self.class.
|
|
976
|
+
norm_style = self.class.border_style!(style)
|
|
724
977
|
@border_props[:diagonal] = { style: norm_style, color: resolve_color(color) }.compact
|
|
725
978
|
@border_props[:diagonal_up] = true if up
|
|
726
979
|
@border_props[:diagonal_down] = true if down
|
|
727
|
-
|
|
980
|
+
nil
|
|
728
981
|
end
|
|
729
982
|
# rubocop:enable Naming/MethodParameterName
|
|
730
983
|
|
|
731
984
|
# --- Alignment Properties ---
|
|
732
985
|
|
|
986
|
+
# Configures or returns alignment properties.
|
|
987
|
+
# When called with 0 arguments/keywords, returns the current alignment Hash.
|
|
988
|
+
# When called with keyword arguments, merges the properties and returns nil.
|
|
989
|
+
#
|
|
990
|
+
# @param horizontal [String, Symbol, nil] Horizontal alignment (:left, :center, :right, :fill, :justify, etc.).
|
|
991
|
+
# @param vertical [String, Symbol, nil] Vertical alignment (:top, :center, :bottom, :justify, :distributed).
|
|
992
|
+
# @param wrap_text [Boolean, nil] Whether to wrap text within the cell.
|
|
993
|
+
# @param text_rotation [Integer, nil] Text rotation in degrees (0-180 or 255 for vertical).
|
|
994
|
+
# @param indent [Integer, nil] Indentation level (0-250).
|
|
995
|
+
# @param shrink_to_fit [Boolean, nil] Whether to shrink text to fit cell width.
|
|
996
|
+
# @param reading_order [Integer, nil] Reading order (0: context, 1: left-to-right, 2: right-to-left).
|
|
997
|
+
# @param justify_last_line [Boolean, nil] Whether to justify the last line of text.
|
|
998
|
+
# @param relative_indent [Integer, nil] Relative indentation level.
|
|
999
|
+
# @return [Hash, void]
|
|
1000
|
+
# @api public
|
|
1001
|
+
#: () -> Hash[Symbol, untyped]
|
|
1002
|
+
#: (?horizontal: (String | Symbol)?, ?vertical: (String | Symbol)?, ?wrap_text: bool?, ?text_rotation: Integer?, ?indent: Integer?, ?shrink_to_fit: bool?, ?reading_order: Integer?, ?justify_last_line: bool?, ?relative_indent: Integer?) -> void
|
|
1003
|
+
def alignment(horizontal: nil, vertical: nil, wrap_text: nil, text_rotation: nil, indent: nil, shrink_to_fit: nil, reading_order: nil, justify_last_line: nil, relative_indent: nil)
|
|
1004
|
+
return @alignment if horizontal.nil? && vertical.nil? && wrap_text.nil? && text_rotation.nil? && indent.nil? && shrink_to_fit.nil? && reading_order.nil? && justify_last_line.nil? && relative_indent.nil?
|
|
1005
|
+
|
|
1006
|
+
self.align_horizontal = horizontal unless horizontal.nil?
|
|
1007
|
+
self.align_vertical = vertical unless vertical.nil?
|
|
1008
|
+
self.wrap_text = wrap_text unless wrap_text.nil?
|
|
1009
|
+
self.text_rotation = text_rotation unless text_rotation.nil?
|
|
1010
|
+
self.indent = indent unless indent.nil?
|
|
1011
|
+
self.shrink_to_fit = shrink_to_fit unless shrink_to_fit.nil?
|
|
1012
|
+
@alignment[:reading_order] = reading_order unless reading_order.nil?
|
|
1013
|
+
@alignment[:justify_last_line] = justify_last_line unless justify_last_line.nil?
|
|
1014
|
+
@alignment[:relative_indent] = relative_indent unless relative_indent.nil?
|
|
1015
|
+
nil
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
# Sets alignment options.
|
|
1019
|
+
#
|
|
1020
|
+
# @param opts [Hash]
|
|
1021
|
+
# @return [Hash]
|
|
1022
|
+
# @api public
|
|
1023
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
1024
|
+
def alignment=(opts)
|
|
1025
|
+
alignment(**opts)
|
|
1026
|
+
opts
|
|
1027
|
+
end
|
|
1028
|
+
|
|
1029
|
+
# Gets horizontal alignment.
|
|
1030
|
+
# @return [String, Symbol, nil]
|
|
1031
|
+
# @api public
|
|
1032
|
+
#: () -> (String | Symbol | nil)
|
|
1033
|
+
def align_horizontal
|
|
1034
|
+
@alignment[:horizontal]
|
|
1035
|
+
end
|
|
1036
|
+
|
|
733
1037
|
# Sets horizontal alignment.
|
|
734
|
-
# @param value [String, Symbol]
|
|
735
|
-
# @return [
|
|
1038
|
+
# @param value [String, Symbol]
|
|
1039
|
+
# @return [String, Symbol]
|
|
736
1040
|
# @api public
|
|
737
|
-
#: (String | Symbol) ->
|
|
738
|
-
def align_horizontal(value)
|
|
1041
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1042
|
+
def align_horizontal=(value)
|
|
739
1043
|
@alignment[:horizontal] = value
|
|
740
|
-
|
|
1044
|
+
end
|
|
1045
|
+
|
|
1046
|
+
# Gets vertical alignment.
|
|
1047
|
+
# @return [String, Symbol, nil]
|
|
1048
|
+
# @api public
|
|
1049
|
+
#: () -> (String | Symbol | nil)
|
|
1050
|
+
def align_vertical
|
|
1051
|
+
@alignment[:vertical]
|
|
741
1052
|
end
|
|
742
1053
|
|
|
743
1054
|
# Sets vertical alignment.
|
|
744
|
-
# @param value [String, Symbol]
|
|
745
|
-
# @return [
|
|
1055
|
+
# @param value [String, Symbol]
|
|
1056
|
+
# @return [String, Symbol]
|
|
746
1057
|
# @api public
|
|
747
|
-
#: (String | Symbol) ->
|
|
748
|
-
def align_vertical(value)
|
|
1058
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1059
|
+
def align_vertical=(value)
|
|
749
1060
|
@alignment[:vertical] = value
|
|
750
|
-
self
|
|
751
1061
|
end
|
|
752
1062
|
|
|
753
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
|
754
1063
|
# Sets text wrapping.
|
|
755
|
-
# @param value [Boolean]
|
|
756
|
-
# @return [
|
|
1064
|
+
# @param value [Boolean]
|
|
1065
|
+
# @return [Boolean]
|
|
757
1066
|
# @api public
|
|
758
|
-
#: (
|
|
759
|
-
def wrap_text(value
|
|
760
|
-
@alignment[:wrap_text] = value
|
|
761
|
-
|
|
1067
|
+
#: (bool value) -> bool
|
|
1068
|
+
def wrap_text=(value)
|
|
1069
|
+
@alignment[:wrap_text] = value ? true : false
|
|
1070
|
+
end
|
|
1071
|
+
|
|
1072
|
+
# Returns whether text wrapping is enabled.
|
|
1073
|
+
# @return [Boolean]
|
|
1074
|
+
# @api public
|
|
1075
|
+
#: () -> bool
|
|
1076
|
+
def wrap_text?
|
|
1077
|
+
@alignment[:wrap_text] ? true : false
|
|
762
1078
|
end
|
|
763
1079
|
|
|
764
1080
|
# Sets shrink to fit.
|
|
765
|
-
# @param value [Boolean]
|
|
766
|
-
# @return [
|
|
1081
|
+
# @param value [Boolean]
|
|
1082
|
+
# @return [Boolean]
|
|
767
1083
|
# @api public
|
|
768
|
-
#: (
|
|
769
|
-
def shrink_to_fit(value
|
|
770
|
-
@alignment[:shrink_to_fit] = value
|
|
771
|
-
|
|
1084
|
+
#: (bool value) -> bool
|
|
1085
|
+
def shrink_to_fit=(value)
|
|
1086
|
+
@alignment[:shrink_to_fit] = value ? true : false
|
|
1087
|
+
end
|
|
1088
|
+
|
|
1089
|
+
# Returns whether shrink to fit is enabled.
|
|
1090
|
+
# @return [Boolean]
|
|
1091
|
+
# @api public
|
|
1092
|
+
#: () -> bool
|
|
1093
|
+
def shrink_to_fit?
|
|
1094
|
+
@alignment[:shrink_to_fit] ? true : false
|
|
1095
|
+
end
|
|
1096
|
+
|
|
1097
|
+
# Gets text rotation.
|
|
1098
|
+
# @return [Numeric, nil]
|
|
1099
|
+
# @api public
|
|
1100
|
+
#: () -> (Numeric | nil)
|
|
1101
|
+
def text_rotation
|
|
1102
|
+
@alignment[:text_rotation]
|
|
772
1103
|
end
|
|
773
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
774
1104
|
|
|
775
1105
|
# Sets text rotation.
|
|
776
|
-
# @param value [Numeric]
|
|
777
|
-
# @return [
|
|
1106
|
+
# @param value [Numeric]
|
|
1107
|
+
# @return [Numeric]
|
|
778
1108
|
# @api public
|
|
779
|
-
#: (Numeric) ->
|
|
780
|
-
def text_rotation(value)
|
|
1109
|
+
#: (Numeric value) -> Numeric
|
|
1110
|
+
def text_rotation=(value)
|
|
781
1111
|
@alignment[:text_rotation] = value
|
|
782
|
-
|
|
1112
|
+
end
|
|
1113
|
+
|
|
1114
|
+
# Gets text indent.
|
|
1115
|
+
# @return [Integer, nil]
|
|
1116
|
+
# @api public
|
|
1117
|
+
#: () -> (Integer | nil)
|
|
1118
|
+
def indent
|
|
1119
|
+
@alignment[:indent]
|
|
783
1120
|
end
|
|
784
1121
|
|
|
785
1122
|
# Sets text indent.
|
|
786
|
-
# @param value [Numeric]
|
|
787
|
-
# @return [
|
|
1123
|
+
# @param value [Numeric]
|
|
1124
|
+
# @return [Numeric]
|
|
788
1125
|
# @api public
|
|
789
|
-
#: (Numeric) ->
|
|
790
|
-
def indent(value)
|
|
1126
|
+
#: (Numeric value) -> Numeric
|
|
1127
|
+
def indent=(value)
|
|
791
1128
|
@alignment[:indent] = value.to_i
|
|
792
|
-
|
|
1129
|
+
end
|
|
1130
|
+
|
|
1131
|
+
# --- Protection Properties ---
|
|
1132
|
+
|
|
1133
|
+
# Configures or returns cell protection properties.
|
|
1134
|
+
# When called with 0 arguments/keywords, returns the current protection Hash.
|
|
1135
|
+
# When called with keyword arguments, merges the properties and returns nil.
|
|
1136
|
+
#
|
|
1137
|
+
# @param locked [Boolean, nil]
|
|
1138
|
+
# @param hidden [Boolean, nil]
|
|
1139
|
+
# @return [Hash, void]
|
|
1140
|
+
# @api public
|
|
1141
|
+
#: () -> Hash[Symbol, untyped]
|
|
1142
|
+
#: (?locked: bool?, ?hidden: bool?) -> void
|
|
1143
|
+
def protection(locked: nil, hidden: nil)
|
|
1144
|
+
return @protection if locked.nil? && hidden.nil?
|
|
1145
|
+
|
|
1146
|
+
self.locked = locked unless locked.nil?
|
|
1147
|
+
self.hidden = hidden unless hidden.nil?
|
|
1148
|
+
nil
|
|
1149
|
+
end
|
|
1150
|
+
|
|
1151
|
+
# Sets protection options.
|
|
1152
|
+
#
|
|
1153
|
+
# @param opts [Hash]
|
|
1154
|
+
# @return [Hash]
|
|
1155
|
+
# @api public
|
|
1156
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
1157
|
+
def protection=(opts)
|
|
1158
|
+
protection(**opts)
|
|
1159
|
+
opts
|
|
1160
|
+
end
|
|
1161
|
+
|
|
1162
|
+
# Sets whether the cell is locked.
|
|
1163
|
+
#
|
|
1164
|
+
# @param value [Boolean]
|
|
1165
|
+
# @return [Boolean]
|
|
1166
|
+
# @api public
|
|
1167
|
+
#: (bool value) -> bool
|
|
1168
|
+
def locked=(value)
|
|
1169
|
+
@protection[:locked] = value ? true : false
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
# Returns whether the cell is locked.
|
|
1173
|
+
# @return [Boolean]
|
|
1174
|
+
# @api public
|
|
1175
|
+
#: () -> bool
|
|
1176
|
+
def locked?
|
|
1177
|
+
@protection[:locked] != false
|
|
1178
|
+
end
|
|
1179
|
+
|
|
1180
|
+
# Sets whether the cell formula is hidden.
|
|
1181
|
+
#
|
|
1182
|
+
# @param value [Boolean]
|
|
1183
|
+
# @return [Boolean]
|
|
1184
|
+
# @api public
|
|
1185
|
+
#: (bool value) -> bool
|
|
1186
|
+
def hidden=(value)
|
|
1187
|
+
@protection[:hidden] = value ? true : false
|
|
1188
|
+
end
|
|
1189
|
+
|
|
1190
|
+
# Returns whether the cell formula is hidden.
|
|
1191
|
+
# @return [Boolean]
|
|
1192
|
+
# @api public
|
|
1193
|
+
#: () -> bool
|
|
1194
|
+
def hidden?
|
|
1195
|
+
@protection[:hidden] ? true : false
|
|
793
1196
|
end
|
|
794
1197
|
|
|
795
1198
|
# --- Number Format ---
|
|
796
1199
|
|
|
1200
|
+
# Gets the number format.
|
|
1201
|
+
# @return [String, Integer, nil]
|
|
1202
|
+
# @api public
|
|
1203
|
+
#: () -> (String | Integer | nil)
|
|
1204
|
+
def number_format
|
|
1205
|
+
@num_fmt_id
|
|
1206
|
+
end
|
|
1207
|
+
|
|
797
1208
|
# Sets the number format.
|
|
798
|
-
# @param num_fmt_id [String, Integer]
|
|
799
|
-
# @return [
|
|
1209
|
+
# @param num_fmt_id [String, Integer]
|
|
1210
|
+
# @return [String, Integer]
|
|
800
1211
|
# @api public
|
|
801
|
-
#: (String | Integer) ->
|
|
802
|
-
def number_format(num_fmt_id)
|
|
1212
|
+
#: (String | Integer num_fmt_id) -> (String | Integer)
|
|
1213
|
+
def number_format=(num_fmt_id)
|
|
803
1214
|
@num_fmt_id = num_fmt_id
|
|
804
|
-
self
|
|
805
1215
|
end
|
|
806
|
-
alias num_fmt number_format
|
|
807
1216
|
|
|
808
1217
|
# Register this style with the given Writer, returning the style_id.
|
|
809
1218
|
# writer:: Xlsxrb::Ooxml::Writer instance
|
|
@@ -830,8 +1239,45 @@ module Xlsxrb
|
|
|
830
1239
|
border_id: border_id
|
|
831
1240
|
}
|
|
832
1241
|
cell_style_opts[:alignment] = @alignment if @alignment.any?
|
|
1242
|
+
cell_style_opts[:protection] = @protection if @protection.any?
|
|
833
1243
|
|
|
834
1244
|
writer.add_cell_style(**cell_style_opts)
|
|
835
1245
|
end
|
|
1246
|
+
|
|
1247
|
+
private
|
|
1248
|
+
|
|
1249
|
+
# Raises ArgumentError for option keys #apply_options! does not know, and for a nested
|
|
1250
|
+
# group (font:, fill:, ...) given together with its flat keys, which would be ignored.
|
|
1251
|
+
#: (Hash[Symbol, untyped] opts) -> void
|
|
1252
|
+
def check_options!(opts)
|
|
1253
|
+
opts.each_key { |key| raise ArgumentError, unknown_option_message(key, OPTION_KEYS, "style option") unless OPTION_KEYS.include?(key) }
|
|
1254
|
+
|
|
1255
|
+
NESTED_OPTION_KEYS.each do |group, allowed|
|
|
1256
|
+
nested = opts[group]
|
|
1257
|
+
next unless nested.is_a?(Hash)
|
|
1258
|
+
|
|
1259
|
+
nested.each_key { |key| raise ArgumentError, unknown_option_message(key, allowed, "#{group}: option") unless allowed.include?(key) }
|
|
1260
|
+
end
|
|
1261
|
+
|
|
1262
|
+
FLAT_KEYS_BY_GROUP.each do |group, flat_keys|
|
|
1263
|
+
next unless opts.key?(group)
|
|
1264
|
+
|
|
1265
|
+
mixed = flat_keys.select { |key| opts.key?(key) }
|
|
1266
|
+
next if mixed.empty?
|
|
1267
|
+
|
|
1268
|
+
raise ArgumentError, "Give #{group} options either as #{group}: { ... } or as flat keys, not both (got #{group}: and #{mixed.map(&:inspect).join(", ")})"
|
|
1269
|
+
end
|
|
1270
|
+
end
|
|
1271
|
+
|
|
1272
|
+
def unknown_option_message(key, allowed, kind)
|
|
1273
|
+
suggestion = DslHelpers.closest_name(key, allowed)
|
|
1274
|
+
message = "Unknown #{kind} #{key.inspect}"
|
|
1275
|
+
message << "; did you mean #{suggestion.to_sym.inspect}?" if suggestion
|
|
1276
|
+
message << " (valid: #{allowed.map(&:inspect).join(", ")})"
|
|
1277
|
+
end
|
|
1278
|
+
|
|
1279
|
+
def resolve_color(color)
|
|
1280
|
+
self.class.resolve_color(color)
|
|
1281
|
+
end
|
|
836
1282
|
end
|
|
837
1283
|
end
|