xlsxrb 0.1.17 → 0.1.18
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 +93 -1
- data/README.md +79 -19
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
- data/lib/xlsxrb/chart_builder.rb +595 -113
- data/lib/xlsxrb/dsl_helpers.rb +72 -20
- data/lib/xlsxrb/elements/cell.rb +243 -56
- data/lib/xlsxrb/elements/column.rb +94 -5
- data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
- data/lib/xlsxrb/elements/image.rb +81 -15
- data/lib/xlsxrb/elements/metadata.rb +2733 -0
- data/lib/xlsxrb/elements/row.rb +130 -46
- data/lib/xlsxrb/elements/styles.rb +184 -76
- data/lib/xlsxrb/elements/types.rb +242 -7
- data/lib/xlsxrb/elements/workbook.rb +171 -82
- data/lib/xlsxrb/elements/worksheet.rb +598 -102
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +4 -0
- data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
- data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
- data/lib/xlsxrb/ooxml/writer.rb +22 -6
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
- data/lib/xlsxrb/stream_row.rb +97 -18
- data/lib/xlsxrb/stream_sheet.rb +706 -190
- data/lib/xlsxrb/stream_writer.rb +1893 -374
- data/lib/xlsxrb/style_builder.rb +774 -111
- data/lib/xlsxrb/utils.rb +66 -106
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +380 -83
- data/lib/xlsxrb/worksheet_builder.rb +1210 -233
- data/lib/xlsxrb.rb +1266 -326
- data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
- data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
- data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
- data/sig/generated/xlsxrb/elements/column.rbs +61 -2
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
- data/sig/generated/xlsxrb/elements/image.rbs +30 -8
- data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
- data/sig/generated/xlsxrb/elements/row.rbs +61 -21
- data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
- data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
- data/sig/generated/xlsxrb/stream_row.rbs +48 -14
- data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
- data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
- data/sig/generated/xlsxrb/style_builder.rbs +389 -79
- data/sig/generated/xlsxrb/utils.rbs +34 -18
- data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
- data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
- data/sig/generated/xlsxrb.rbs +257 -49
- metadata +3 -1
data/lib/xlsxrb/style_builder.rb
CHANGED
|
@@ -232,6 +232,8 @@ module Xlsxrb
|
|
|
232
232
|
sub: "subscript",
|
|
233
233
|
baseline: "baseline"
|
|
234
234
|
}.freeze
|
|
235
|
+
OMITTED = Object.new.freeze
|
|
236
|
+
private_constant :COLORS, :CSS_COLORS, :BORDER_STYLES, :BORDER_INDEX_MAP, :OMITTED
|
|
235
237
|
|
|
236
238
|
# Normalizes a color definition (CSS color name, hex code, or RGB integer) to an OpenXML hex color string.
|
|
237
239
|
#
|
|
@@ -245,7 +247,7 @@ module Xlsxrb
|
|
|
245
247
|
# @param color [String, Symbol, Integer, nil]
|
|
246
248
|
# @param alpha [Boolean] Whether to include the alpha channel ("AARRGGBB" vs "RRGGBB").
|
|
247
249
|
# @return [String, nil]
|
|
248
|
-
# @api
|
|
250
|
+
# @api private
|
|
249
251
|
#: (String | Symbol | Integer | nil color, ?alpha: bool) -> String?
|
|
250
252
|
def self.normalize_color(color, alpha: true)
|
|
251
253
|
return nil if color.nil?
|
|
@@ -299,7 +301,7 @@ module Xlsxrb
|
|
|
299
301
|
#
|
|
300
302
|
# @param style [Symbol, String, Integer, nil]
|
|
301
303
|
# @return [Symbol, nil]
|
|
302
|
-
# @api
|
|
304
|
+
# @api private
|
|
303
305
|
#: (Symbol | String | Integer | nil style) -> Symbol?
|
|
304
306
|
def self.normalize_border_style(style)
|
|
305
307
|
return nil if style.nil?
|
|
@@ -331,10 +333,6 @@ module Xlsxrb
|
|
|
331
333
|
color.to_s
|
|
332
334
|
end
|
|
333
335
|
|
|
334
|
-
def resolve_color(color)
|
|
335
|
-
self.class.resolve_color(color)
|
|
336
|
-
end
|
|
337
|
-
|
|
338
336
|
#: (?String? name) -> void
|
|
339
337
|
def initialize(name = nil)
|
|
340
338
|
@name = name
|
|
@@ -343,9 +341,23 @@ module Xlsxrb
|
|
|
343
341
|
@border_props = {}
|
|
344
342
|
@num_fmt_id = nil
|
|
345
343
|
@alignment = {}
|
|
344
|
+
@protection = {}
|
|
346
345
|
end
|
|
347
346
|
|
|
348
|
-
|
|
347
|
+
#: (String | Symbol)?
|
|
348
|
+
attr_reader :name
|
|
349
|
+
|
|
350
|
+
# @api private
|
|
351
|
+
#: Hash[Symbol, untyped]
|
|
352
|
+
attr_reader :font_props
|
|
353
|
+
|
|
354
|
+
# @api private
|
|
355
|
+
#: Hash[Symbol, untyped]
|
|
356
|
+
attr_reader :fill_props
|
|
357
|
+
|
|
358
|
+
# @api private
|
|
359
|
+
#: Hash[Symbol, untyped]
|
|
360
|
+
attr_reader :border_props
|
|
349
361
|
|
|
350
362
|
# Applies option-style definitions so callers can use add_style(name, **opts)
|
|
351
363
|
# as an alternative to block-based fluent chaining.
|
|
@@ -360,25 +372,69 @@ module Xlsxrb
|
|
|
360
372
|
font_opts = opts[:font] || {}
|
|
361
373
|
bold(font_opts[:bold]) if font_opts.key?(:bold)
|
|
362
374
|
italic(font_opts[:italic]) if font_opts.key?(:italic)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
375
|
+
if font_opts.key?(:font_size)
|
|
376
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_size is deprecated; use :size instead.", uplevel: 1
|
|
377
|
+
font_size(font_opts[:font_size])
|
|
378
|
+
elsif font_opts.key?(:size)
|
|
379
|
+
font_size(font_opts[:size])
|
|
380
|
+
elsif font_opts.key?(:sz)
|
|
381
|
+
warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
|
|
382
|
+
font_size(font_opts[:sz])
|
|
383
|
+
end
|
|
384
|
+
if font_opts.key?(:font_name)
|
|
385
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_name is deprecated; use :name instead.", uplevel: 1
|
|
386
|
+
font_name(font_opts[:font_name])
|
|
387
|
+
elsif font_opts.key?(:name)
|
|
388
|
+
font_name(font_opts[:name])
|
|
389
|
+
end
|
|
390
|
+
if font_opts.key?(:font_color)
|
|
391
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_color is deprecated; use :color instead.", uplevel: 1
|
|
392
|
+
font_color(font_opts[:font_color])
|
|
393
|
+
elsif font_opts.key?(:color)
|
|
394
|
+
font_color(font_opts[:color])
|
|
395
|
+
end
|
|
366
396
|
underline(font_opts[:underline]) if font_opts.key?(:underline)
|
|
367
397
|
strike(font_opts[:strike]) if font_opts.key?(:strike)
|
|
368
|
-
|
|
369
|
-
|
|
398
|
+
if font_opts.key?(:vertical_align)
|
|
399
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
|
|
400
|
+
vert_align(font_opts[:vertical_align])
|
|
401
|
+
elsif font_opts.key?(:vert_align)
|
|
402
|
+
vert_align(font_opts[:vert_align])
|
|
403
|
+
end
|
|
370
404
|
superscript(font_opts[:superscript]) if font_opts.key?(:superscript)
|
|
371
405
|
subscript(font_opts[:subscript]) if font_opts.key?(:subscript)
|
|
372
406
|
else
|
|
373
407
|
bold(opts[:bold]) if opts.key?(:bold)
|
|
374
408
|
italic(opts[:italic]) if opts.key?(:italic)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
409
|
+
if opts.key?(:size)
|
|
410
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder option :size is deprecated; use :font_size instead.", uplevel: 1
|
|
411
|
+
font_size(opts[:size])
|
|
412
|
+
elsif opts.key?(:font_size)
|
|
413
|
+
font_size(opts[:font_size])
|
|
414
|
+
elsif opts.key?(:sz)
|
|
415
|
+
warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
|
|
416
|
+
font_size(opts[:sz])
|
|
417
|
+
end
|
|
418
|
+
if opts.key?(:name)
|
|
419
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder option :name is deprecated; use :font_name instead.", uplevel: 1
|
|
420
|
+
font_name(opts[:name])
|
|
421
|
+
elsif opts.key?(:font_name)
|
|
422
|
+
font_name(opts[:font_name])
|
|
423
|
+
end
|
|
424
|
+
if opts.key?(:color)
|
|
425
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder option :color is deprecated; use :font_color instead.", uplevel: 1
|
|
426
|
+
font_color(opts[:color])
|
|
427
|
+
elsif opts.key?(:font_color)
|
|
428
|
+
font_color(opts[:font_color])
|
|
429
|
+
end
|
|
378
430
|
underline(opts[:underline]) if opts.key?(:underline)
|
|
379
431
|
strike(opts[:strike]) if opts.key?(:strike)
|
|
380
|
-
|
|
381
|
-
|
|
432
|
+
if opts.key?(:vertical_align)
|
|
433
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
|
|
434
|
+
vert_align(opts[:vertical_align])
|
|
435
|
+
elsif opts.key?(:vert_align)
|
|
436
|
+
vert_align(opts[:vert_align])
|
|
437
|
+
end
|
|
382
438
|
superscript(opts[:superscript]) if opts.key?(:superscript)
|
|
383
439
|
subscript(opts[:subscript]) if opts.key?(:subscript)
|
|
384
440
|
end
|
|
@@ -422,7 +478,12 @@ module Xlsxrb
|
|
|
422
478
|
border_bottom(**opts[:border_bottom]) if opts.key?(:border_bottom) && opts[:border_bottom]
|
|
423
479
|
end
|
|
424
480
|
|
|
425
|
-
|
|
481
|
+
if opts.key?(:number_format_id)
|
|
482
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder option :number_format_id is deprecated; use :number_format instead.", uplevel: 1
|
|
483
|
+
number_format(opts[:number_format_id])
|
|
484
|
+
elsif opts.key?(:number_format)
|
|
485
|
+
number_format(opts[:number_format])
|
|
486
|
+
end
|
|
426
487
|
|
|
427
488
|
if opts.key?(:alignment)
|
|
428
489
|
align_opts = opts[:alignment] || {}
|
|
@@ -441,6 +502,15 @@ module Xlsxrb
|
|
|
441
502
|
shrink_to_fit(opts[:shrink_to_fit]) if opts.key?(:shrink_to_fit)
|
|
442
503
|
end
|
|
443
504
|
|
|
505
|
+
if opts.key?(:protection)
|
|
506
|
+
prot_opts = opts[:protection] || {}
|
|
507
|
+
locked(prot_opts[:locked]) if prot_opts.key?(:locked)
|
|
508
|
+
hidden(prot_opts[:hidden]) if prot_opts.key?(:hidden)
|
|
509
|
+
else
|
|
510
|
+
locked(opts[:locked]) if opts.key?(:locked)
|
|
511
|
+
hidden(opts[:hidden]) if opts.key?(:hidden)
|
|
512
|
+
end
|
|
513
|
+
|
|
444
514
|
self
|
|
445
515
|
end
|
|
446
516
|
|
|
@@ -450,79 +520,234 @@ module Xlsxrb
|
|
|
450
520
|
# @param opts [Hash] The font properties.
|
|
451
521
|
# @return [self]
|
|
452
522
|
# @api public
|
|
453
|
-
#: (**untyped) -> self
|
|
523
|
+
#: (**untyped) -> (self | Hash[Symbol, untyped])
|
|
454
524
|
def font(**opts)
|
|
525
|
+
return @font_props if opts.empty?
|
|
526
|
+
|
|
455
527
|
bold(opts[:bold]) if opts.key?(:bold)
|
|
456
528
|
italic(opts[:italic]) if opts.key?(:italic)
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
529
|
+
if opts.key?(:font_size)
|
|
530
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_size is deprecated; use :size instead.", uplevel: 1
|
|
531
|
+
font_size(opts[:font_size])
|
|
532
|
+
elsif opts.key?(:size)
|
|
533
|
+
font_size(opts[:size])
|
|
534
|
+
elsif opts.key?(:sz)
|
|
535
|
+
warn "[DEPRECATION] :sz is deprecated; use :font_size or :size instead.", uplevel: 1
|
|
536
|
+
font_size(opts[:sz])
|
|
537
|
+
end
|
|
538
|
+
if opts.key?(:font_name)
|
|
539
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_name is deprecated; use :name instead.", uplevel: 1
|
|
540
|
+
font_name(opts[:font_name])
|
|
541
|
+
elsif opts.key?(:name)
|
|
542
|
+
font_name(opts[:name])
|
|
543
|
+
end
|
|
544
|
+
if opts.key?(:font_color)
|
|
545
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :font_color is deprecated; use :color instead.", uplevel: 1
|
|
546
|
+
font_color(opts[:font_color])
|
|
547
|
+
elsif opts.key?(:color)
|
|
548
|
+
font_color(opts[:color])
|
|
549
|
+
end
|
|
460
550
|
underline(opts[:underline]) if opts.key?(:underline)
|
|
461
551
|
strike(opts[:strike]) if opts.key?(:strike)
|
|
462
|
-
|
|
463
|
-
|
|
552
|
+
if opts.key?(:vertical_align)
|
|
553
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder font option :vertical_align is deprecated; use :vert_align instead.", uplevel: 1
|
|
554
|
+
vert_align(opts[:vertical_align])
|
|
555
|
+
elsif opts.key?(:vert_align)
|
|
556
|
+
vert_align(opts[:vert_align])
|
|
557
|
+
end
|
|
464
558
|
superscript(opts[:superscript]) if opts.key?(:superscript)
|
|
465
559
|
subscript(opts[:subscript]) if opts.key?(:subscript)
|
|
466
560
|
self
|
|
467
561
|
end
|
|
468
562
|
|
|
469
|
-
|
|
563
|
+
def font=(opts)
|
|
564
|
+
font(**opts)
|
|
565
|
+
end
|
|
566
|
+
|
|
470
567
|
# Sets the font to bold.
|
|
471
568
|
# @param value [Boolean] Whether to apply bold.
|
|
472
569
|
# @return [self]
|
|
473
570
|
# @api public
|
|
474
|
-
#: (?
|
|
475
|
-
def bold(value =
|
|
476
|
-
|
|
571
|
+
#: (?untyped) -> (self | bool)
|
|
572
|
+
def bold(value = OMITTED)
|
|
573
|
+
if value.equal?(OMITTED)
|
|
574
|
+
return bold? unless @font_props[:bold].nil?
|
|
575
|
+
|
|
576
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#bold with zero arguments as a mutator is deprecated; pass true explicitly (e.g. bold(true))", uplevel: 1)
|
|
577
|
+
@font_props[:bold] = true
|
|
578
|
+
return self
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
@font_props[:bold] = value ? true : false
|
|
477
582
|
self
|
|
478
583
|
end
|
|
479
584
|
|
|
585
|
+
# Sets the font to bold.
|
|
586
|
+
# @param value [Boolean]
|
|
587
|
+
# @return [Boolean]
|
|
588
|
+
# @api public
|
|
589
|
+
#: (bool value) -> bool
|
|
590
|
+
def bold=(value)
|
|
591
|
+
@font_props[:bold] = value
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
# Returns whether bold is enabled.
|
|
595
|
+
# @return [Boolean]
|
|
596
|
+
# @api public
|
|
597
|
+
#: () -> bool
|
|
598
|
+
def bold?
|
|
599
|
+
@font_props[:bold] ? true : false
|
|
600
|
+
end
|
|
601
|
+
|
|
480
602
|
# Sets the font to italic.
|
|
481
603
|
# @param value [Boolean] Whether to apply italic.
|
|
482
604
|
# @return [self]
|
|
483
605
|
# @api public
|
|
484
|
-
#: (?
|
|
485
|
-
def italic(value =
|
|
486
|
-
|
|
606
|
+
#: (?untyped) -> (self | bool)
|
|
607
|
+
def italic(value = OMITTED)
|
|
608
|
+
if value.equal?(OMITTED)
|
|
609
|
+
return italic? unless @font_props[:italic].nil?
|
|
610
|
+
|
|
611
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#italic with zero arguments as a mutator is deprecated; pass true explicitly (e.g. italic(true))", uplevel: 1)
|
|
612
|
+
@font_props[:italic] = true
|
|
613
|
+
return self
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
@font_props[:italic] = value ? true : false
|
|
487
617
|
self
|
|
488
618
|
end
|
|
489
619
|
|
|
490
|
-
# Sets the font
|
|
491
|
-
# @param
|
|
492
|
-
# @return [
|
|
620
|
+
# Sets the font to italic.
|
|
621
|
+
# @param value [Boolean]
|
|
622
|
+
# @return [Boolean]
|
|
623
|
+
# @api public
|
|
624
|
+
#: (bool value) -> bool
|
|
625
|
+
def italic=(value)
|
|
626
|
+
@font_props[:italic] = value
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
# Returns whether italic is enabled.
|
|
630
|
+
# @return [Boolean]
|
|
493
631
|
# @api public
|
|
494
|
-
#: (
|
|
495
|
-
def
|
|
496
|
-
@font_props[:
|
|
632
|
+
#: () -> bool
|
|
633
|
+
def italic?
|
|
634
|
+
@font_props[:italic] ? true : false
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
# Sets or gets the font size in points.
|
|
638
|
+
# @param size_value [Integer, Float, nil] The size in points (supports fractional sizes such as 10.5).
|
|
639
|
+
# @return [Integer, Float, self, nil]
|
|
640
|
+
# @api public
|
|
641
|
+
#: (?Numeric? size_value) -> (Numeric | self | nil)
|
|
642
|
+
def font_size(size_value = nil)
|
|
643
|
+
if size_value.nil?
|
|
644
|
+
@font_props[:size] || @font_props[:sz]
|
|
645
|
+
else
|
|
646
|
+
val = size_value.is_a?(Float) && (size_value % 1).zero? ? size_value.to_i : size_value
|
|
647
|
+
@font_props[:size] = val
|
|
648
|
+
@font_props[:sz] = val
|
|
649
|
+
self
|
|
650
|
+
end
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
# Sets the font size in points.
|
|
654
|
+
# @param size_value [Integer, Float] The size in points (supports fractional sizes such as 10.5).
|
|
655
|
+
# @return [Integer, Float]
|
|
656
|
+
# @api public
|
|
657
|
+
#: (Numeric size_value) -> Numeric
|
|
658
|
+
def font_size=(size_value)
|
|
659
|
+
val = size_value.is_a?(Float) && (size_value % 1).zero? ? size_value.to_i : size_value
|
|
660
|
+
@font_props[:size] = val
|
|
661
|
+
@font_props[:sz] = val
|
|
662
|
+
size_value
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
|
|
666
|
+
#: (?Numeric? size_value) -> (Numeric | self | nil)
|
|
667
|
+
def size(size_value = nil)
|
|
668
|
+
warn "[DEPRECATION] #size is deprecated; use #font_size instead.", uplevel: 1
|
|
669
|
+
font_size(size_value)
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
# @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
|
|
673
|
+
#: (Numeric size_value) -> Numeric
|
|
674
|
+
def size=(size_value)
|
|
675
|
+
warn "[DEPRECATION] #size= is deprecated; use #font_size= instead.", uplevel: 1
|
|
676
|
+
self.font_size = size_value
|
|
677
|
+
end
|
|
678
|
+
|
|
679
|
+
# @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
|
|
680
|
+
#: (?Numeric? size_value) -> (Numeric | self | nil)
|
|
681
|
+
def sz(size_value = nil)
|
|
682
|
+
warn "[DEPRECATION] #sz is deprecated; use #font_size instead.", uplevel: 1
|
|
683
|
+
font_size(size_value)
|
|
684
|
+
end
|
|
685
|
+
|
|
686
|
+
# @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
|
|
687
|
+
#: (Numeric size_value) -> Numeric
|
|
688
|
+
def sz=(size_value)
|
|
689
|
+
warn "[DEPRECATION] #sz= is deprecated; use #font_size= instead.", uplevel: 1
|
|
690
|
+
self.font_size = size_value
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
# Sets the font name.
|
|
694
|
+
# Gets or sets the font name.
|
|
695
|
+
# @param name [String, Object] The font name.
|
|
696
|
+
# @return [String, self, nil]
|
|
697
|
+
# @api public
|
|
698
|
+
#: (?untyped name) -> (String | self | nil)
|
|
699
|
+
def font_name(name = OMITTED)
|
|
700
|
+
return @font_props[:name] if name.equal?(OMITTED)
|
|
701
|
+
|
|
702
|
+
@font_props[:name] = name
|
|
497
703
|
self
|
|
498
704
|
end
|
|
499
705
|
|
|
500
706
|
# Sets the font name.
|
|
501
|
-
# @param name [String]
|
|
502
|
-
# @return [
|
|
707
|
+
# @param name [String]
|
|
708
|
+
# @return [String]
|
|
503
709
|
# @api public
|
|
504
|
-
#: (String) ->
|
|
505
|
-
def font_name(name)
|
|
710
|
+
#: (String name) -> String
|
|
711
|
+
def font_name=(name)
|
|
506
712
|
@font_props[:name] = name
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
# Gets or sets the font color.
|
|
716
|
+
# @param color [String, Symbol, Object] The color.
|
|
717
|
+
# @return [String, Symbol, self, nil]
|
|
718
|
+
# @api public
|
|
719
|
+
#: (?untyped color) -> (String | Symbol | self | nil)
|
|
720
|
+
def font_color(color = OMITTED)
|
|
721
|
+
return @font_props[:color] if color.equal?(OMITTED)
|
|
722
|
+
|
|
723
|
+
@font_props[:color] = resolve_color(color)
|
|
507
724
|
self
|
|
508
725
|
end
|
|
509
726
|
|
|
510
727
|
# Sets the font color.
|
|
511
|
-
# @param color [String, Symbol]
|
|
512
|
-
# @return [
|
|
728
|
+
# @param color [String, Symbol]
|
|
729
|
+
# @return [String, Symbol]
|
|
513
730
|
# @api public
|
|
514
|
-
#: (String | Symbol) ->
|
|
515
|
-
def font_color(color)
|
|
731
|
+
#: (String | Symbol color) -> (String | Symbol)
|
|
732
|
+
def font_color=(color)
|
|
516
733
|
@font_props[:color] = resolve_color(color)
|
|
517
|
-
|
|
734
|
+
color
|
|
518
735
|
end
|
|
519
736
|
|
|
520
737
|
# Sets the font underline style.
|
|
521
738
|
# @param val [String, Symbol, Boolean] The underline style (e.g., 'single', :double, :single_accounting, :double_accounting).
|
|
522
739
|
# @return [self]
|
|
523
740
|
# @api public
|
|
524
|
-
#: (?String | Symbol | bool
|
|
525
|
-
def underline(val =
|
|
741
|
+
#: (?untyped) -> (self | String | Symbol | bool | nil)
|
|
742
|
+
def underline(val = OMITTED)
|
|
743
|
+
if val.equal?(OMITTED)
|
|
744
|
+
return @font_props[:underline] unless @font_props[:underline].nil?
|
|
745
|
+
|
|
746
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#underline with zero arguments as a mutator is deprecated; pass true explicitly (e.g. underline(true))", uplevel: 1)
|
|
747
|
+
@font_props[:underline] = "single"
|
|
748
|
+
return self
|
|
749
|
+
end
|
|
750
|
+
|
|
526
751
|
mapped = if [true, "single"].include?(val)
|
|
527
752
|
"single"
|
|
528
753
|
elsif val == false
|
|
@@ -534,48 +759,130 @@ module Xlsxrb
|
|
|
534
759
|
self
|
|
535
760
|
end
|
|
536
761
|
|
|
762
|
+
# Sets the font underline style.
|
|
763
|
+
# @param val [String, Symbol, Boolean]
|
|
764
|
+
# @return [String, Symbol, Boolean]
|
|
765
|
+
# @api public
|
|
766
|
+
#: (String | Symbol | bool val) -> (String | Symbol | bool)
|
|
767
|
+
def underline=(val)
|
|
768
|
+
underline(val)
|
|
769
|
+
val
|
|
770
|
+
end
|
|
771
|
+
|
|
772
|
+
# Returns whether underline is enabled.
|
|
773
|
+
# @return [Boolean]
|
|
774
|
+
# @api public
|
|
775
|
+
#: () -> bool
|
|
776
|
+
def underline?
|
|
777
|
+
!@font_props[:underline].nil? && @font_props[:underline] != false
|
|
778
|
+
end
|
|
779
|
+
|
|
537
780
|
# Sets the font strikethrough.
|
|
538
781
|
# @param value [Boolean] Whether to apply strike.
|
|
539
782
|
# @return [self]
|
|
540
783
|
# @api public
|
|
541
|
-
#: (?
|
|
542
|
-
def strike(value =
|
|
543
|
-
|
|
784
|
+
#: (?untyped) -> (self | bool)
|
|
785
|
+
def strike(value = OMITTED)
|
|
786
|
+
if value.equal?(OMITTED)
|
|
787
|
+
return strike? unless @font_props[:strike].nil?
|
|
788
|
+
|
|
789
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#strike with zero arguments as a mutator is deprecated; pass true explicitly (e.g. strike(true))", uplevel: 1)
|
|
790
|
+
@font_props[:strike] = true
|
|
791
|
+
return self
|
|
792
|
+
end
|
|
793
|
+
|
|
794
|
+
@font_props[:strike] = value ? true : false
|
|
544
795
|
self
|
|
545
796
|
end
|
|
546
797
|
|
|
547
|
-
# Sets the
|
|
548
|
-
# @param value [
|
|
549
|
-
# @return [
|
|
798
|
+
# Sets the font strikethrough.
|
|
799
|
+
# @param value [Boolean]
|
|
800
|
+
# @return [Boolean]
|
|
801
|
+
# @api public
|
|
802
|
+
#: (bool value) -> bool
|
|
803
|
+
def strike=(value)
|
|
804
|
+
@font_props[:strike] = value
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
# Returns whether strikethrough is enabled.
|
|
808
|
+
# @return [Boolean]
|
|
550
809
|
# @api public
|
|
551
|
-
#: (
|
|
552
|
-
def
|
|
810
|
+
#: () -> bool
|
|
811
|
+
def strike?
|
|
812
|
+
@font_props[:strike] ? true : false
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
# Gets or sets the vertical alignment of the font.
|
|
816
|
+
# @param value [String, Symbol, Object] The alignment value ('superscript', 'subscript', 'baseline', :superscript, :subscript).
|
|
817
|
+
# @return [String, self, nil]
|
|
818
|
+
# @api public
|
|
819
|
+
#: (?untyped value) -> (String | self | nil)
|
|
820
|
+
def vert_align(value = OMITTED)
|
|
821
|
+
return @font_props[:vert_align] if value.equal?(OMITTED)
|
|
822
|
+
|
|
553
823
|
mapped = VERT_ALIGN_MAP[value.to_sym] || value.to_s
|
|
554
824
|
@font_props[:vert_align] = mapped
|
|
555
825
|
self
|
|
556
826
|
end
|
|
557
827
|
|
|
828
|
+
def vert_align=(value)
|
|
829
|
+
vert_align(value)
|
|
830
|
+
value
|
|
831
|
+
end
|
|
832
|
+
|
|
558
833
|
# Sets the font to superscript.
|
|
559
834
|
# @param value [Boolean] Whether to apply superscript.
|
|
560
835
|
# @return [self]
|
|
561
836
|
# @api public
|
|
562
|
-
#: (?
|
|
563
|
-
def superscript(value =
|
|
837
|
+
#: (?untyped) -> (self | bool)
|
|
838
|
+
def superscript(value = OMITTED)
|
|
839
|
+
if value.equal?(OMITTED)
|
|
840
|
+
return superscript? unless @font_props[:vert_align].nil?
|
|
841
|
+
|
|
842
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#superscript with zero arguments as a mutator is deprecated; pass true explicitly (e.g. superscript(true))", uplevel: 1)
|
|
843
|
+
@font_props[:vert_align] = "superscript"
|
|
844
|
+
return self
|
|
845
|
+
end
|
|
846
|
+
|
|
564
847
|
@font_props[:vert_align] = value ? "superscript" : "baseline"
|
|
565
848
|
self
|
|
566
849
|
end
|
|
567
850
|
|
|
851
|
+
def superscript=(value)
|
|
852
|
+
superscript(value)
|
|
853
|
+
value
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
def superscript?
|
|
857
|
+
@font_props[:vert_align] == "superscript"
|
|
858
|
+
end
|
|
859
|
+
|
|
568
860
|
# Sets the font to subscript.
|
|
569
861
|
# @param value [Boolean] Whether to apply subscript.
|
|
570
862
|
# @return [self]
|
|
571
863
|
# @api public
|
|
572
|
-
#: (?
|
|
573
|
-
def subscript(value =
|
|
864
|
+
#: (?untyped) -> (self | bool)
|
|
865
|
+
def subscript(value = OMITTED)
|
|
866
|
+
if value.equal?(OMITTED)
|
|
867
|
+
return subscript? unless @font_props[:vert_align].nil?
|
|
868
|
+
|
|
869
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#subscript with zero arguments as a mutator is deprecated; pass true explicitly (e.g. subscript(true))", uplevel: 1)
|
|
870
|
+
@font_props[:vert_align] = "subscript"
|
|
871
|
+
return self
|
|
872
|
+
end
|
|
873
|
+
|
|
574
874
|
@font_props[:vert_align] = value ? "subscript" : "baseline"
|
|
575
875
|
self
|
|
576
876
|
end
|
|
577
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
578
877
|
|
|
878
|
+
def subscript=(value)
|
|
879
|
+
subscript(value)
|
|
880
|
+
value
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
def subscript?
|
|
884
|
+
@font_props[:vert_align] == "subscript"
|
|
885
|
+
end
|
|
579
886
|
# --- Fill Properties ---
|
|
580
887
|
|
|
581
888
|
# Sets the fill pattern.
|
|
@@ -590,28 +897,63 @@ module Xlsxrb
|
|
|
590
897
|
# @param bg_color [String, Symbol, nil] The background color.
|
|
591
898
|
# @return [self]
|
|
592
899
|
# @api public
|
|
593
|
-
#: (
|
|
594
|
-
def fill_pattern(pattern, fg_color: nil, bg_color: nil)
|
|
900
|
+
#: (?untyped pattern, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> untyped
|
|
901
|
+
def fill_pattern(pattern = OMITTED, fg_color: nil, bg_color: nil)
|
|
902
|
+
return @fill_props[:pattern] if pattern.equal?(OMITTED)
|
|
903
|
+
|
|
595
904
|
@fill_props[:pattern] = pattern
|
|
596
905
|
@fill_props[:fg_color] = fg_color if fg_color
|
|
597
906
|
@fill_props[:bg_color] = bg_color if bg_color
|
|
598
907
|
self
|
|
599
908
|
end
|
|
600
909
|
|
|
601
|
-
# Sets
|
|
602
|
-
# @param
|
|
603
|
-
# @return [
|
|
910
|
+
# Sets the fill pattern.
|
|
911
|
+
# @param pattern [String, Symbol, Hash]
|
|
912
|
+
# @return [Object]
|
|
913
|
+
# @api public
|
|
914
|
+
#: (untyped pattern) -> untyped
|
|
915
|
+
def fill_pattern=(pattern)
|
|
916
|
+
if pattern.is_a?(Hash)
|
|
917
|
+
fill_pattern(pattern[:pattern] || "solid", fg_color: pattern[:fg_color], bg_color: pattern[:bg_color])
|
|
918
|
+
else
|
|
919
|
+
@fill_props[:pattern] = pattern
|
|
920
|
+
end
|
|
921
|
+
pattern
|
|
922
|
+
end
|
|
923
|
+
|
|
924
|
+
# Gets or sets a solid fill color.
|
|
925
|
+
# @param color [String, Symbol, Object] The color.
|
|
926
|
+
# @return [String, Symbol, self, nil]
|
|
604
927
|
# @api public
|
|
605
|
-
#: (String | Symbol
|
|
606
|
-
def fill_color(color)
|
|
928
|
+
#: (?untyped color) -> (String | Symbol | self | nil)
|
|
929
|
+
def fill_color(color = OMITTED)
|
|
930
|
+
return @fill_props[:fg_color] if color.equal?(OMITTED)
|
|
931
|
+
|
|
607
932
|
@fill_props[:pattern] = "solid"
|
|
608
933
|
@fill_props[:fg_color] = resolve_color(color)
|
|
609
934
|
self
|
|
610
935
|
end
|
|
611
936
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
937
|
+
# Sets a solid fill color.
|
|
938
|
+
# @param color [String, Symbol]
|
|
939
|
+
# @return [String, Symbol]
|
|
940
|
+
# @api public
|
|
941
|
+
#: (String | Symbol color) -> (String | Symbol)
|
|
942
|
+
def fill_color=(color)
|
|
943
|
+
fill_color(color)
|
|
944
|
+
color
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
#: (?pattern: untyped, ?fg_color: String | Symbol | nil, ?bg_color: String | Symbol | nil) -> (self | Hash[Symbol, untyped])
|
|
948
|
+
def fill(pattern: OMITTED, fg_color: nil, bg_color: nil)
|
|
949
|
+
return @fill_props if pattern.equal?(OMITTED) && fg_color.nil? && bg_color.nil?
|
|
950
|
+
|
|
951
|
+
pat = pattern.equal?(OMITTED) ? "solid" : pattern
|
|
952
|
+
fill_pattern(pat, fg_color: resolve_color(fg_color), bg_color: resolve_color(bg_color))
|
|
953
|
+
end
|
|
954
|
+
|
|
955
|
+
def fill=(opts)
|
|
956
|
+
fill(**opts)
|
|
615
957
|
end
|
|
616
958
|
|
|
617
959
|
# Sets a gradient fill.
|
|
@@ -620,8 +962,10 @@ module Xlsxrb
|
|
|
620
962
|
# @param stops [Array] The gradient stops.
|
|
621
963
|
# @return [self]
|
|
622
964
|
# @api public
|
|
623
|
-
#: (type:
|
|
624
|
-
def fill_gradient(type
|
|
965
|
+
#: (?type: untyped, ?degree: Numeric | nil, ?stops: Array[untyped]) -> (self | Hash[Symbol, untyped] | nil)
|
|
966
|
+
def fill_gradient(type: OMITTED, degree: nil, stops: [])
|
|
967
|
+
return @fill_props[:gradient] if type.equal?(OMITTED)
|
|
968
|
+
|
|
625
969
|
@fill_props[:gradient] = {
|
|
626
970
|
type: type,
|
|
627
971
|
degree: degree,
|
|
@@ -633,19 +977,31 @@ module Xlsxrb
|
|
|
633
977
|
# --- Border Properties ---
|
|
634
978
|
|
|
635
979
|
# Configures multiple border properties.
|
|
636
|
-
# @param
|
|
980
|
+
# @param all [Hash, nil]
|
|
981
|
+
# @param left [Hash, nil]
|
|
982
|
+
# @param right [Hash, nil]
|
|
983
|
+
# @param top [Hash, nil]
|
|
984
|
+
# @param bottom [Hash, nil]
|
|
985
|
+
# @param diagonal [Hash, nil]
|
|
637
986
|
# @return [self]
|
|
638
987
|
# @api public
|
|
639
|
-
#: (
|
|
640
|
-
def border(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
988
|
+
#: (?all: Hash[Symbol, untyped]?, ?left: Hash[Symbol, untyped]?, ?right: Hash[Symbol, untyped]?, ?top: Hash[Symbol, untyped]?, ?bottom: Hash[Symbol, untyped]?, ?diagonal: Hash[Symbol, untyped]?) -> (self | Hash[Symbol, untyped])
|
|
989
|
+
def border(all: nil, left: nil, right: nil, top: nil, bottom: nil, diagonal: nil)
|
|
990
|
+
return @border_props if all.nil? && left.nil? && right.nil? && top.nil? && bottom.nil? && diagonal.nil?
|
|
991
|
+
|
|
992
|
+
border_all(**all) if all
|
|
993
|
+
border_left(**left) if left
|
|
994
|
+
border_right(**right) if right
|
|
995
|
+
border_top(**top) if top
|
|
996
|
+
border_bottom(**bottom) if bottom
|
|
997
|
+
border_diagonal(**diagonal) if diagonal
|
|
646
998
|
self
|
|
647
999
|
end
|
|
648
1000
|
|
|
1001
|
+
def border=(opts)
|
|
1002
|
+
border(**opts)
|
|
1003
|
+
end
|
|
1004
|
+
|
|
649
1005
|
# Sets all borders.
|
|
650
1006
|
# @param style [String, Symbol, Integer] The border style.
|
|
651
1007
|
# @param color [String, Symbol, nil] The color.
|
|
@@ -730,80 +1086,380 @@ module Xlsxrb
|
|
|
730
1086
|
|
|
731
1087
|
# --- Alignment Properties ---
|
|
732
1088
|
|
|
1089
|
+
# Configures or returns alignment properties.
|
|
1090
|
+
# When called with 0 arguments/keywords, returns the current alignment Hash.
|
|
1091
|
+
# When called with keyword arguments, merges the properties and returns self.
|
|
1092
|
+
#
|
|
1093
|
+
# @param horizontal [String, Symbol, nil]
|
|
1094
|
+
# @param vertical [String, Symbol, nil]
|
|
1095
|
+
# @param wrap_text [Boolean, nil]
|
|
1096
|
+
# @param text_rotation [Integer, nil]
|
|
1097
|
+
# @param indent [Integer, nil]
|
|
1098
|
+
# @param shrink_to_fit [Boolean, nil]
|
|
1099
|
+
# @param reading_order [Integer, nil]
|
|
1100
|
+
# @param justify_last_line [Boolean, nil]
|
|
1101
|
+
# @param relative_indent [Integer, nil]
|
|
1102
|
+
# @return [Hash, self]
|
|
1103
|
+
# @api public
|
|
1104
|
+
#: (?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?) -> (Hash[Symbol, untyped] | self)
|
|
1105
|
+
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)
|
|
1106
|
+
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?
|
|
1107
|
+
|
|
1108
|
+
align_horizontal(horizontal) unless horizontal.nil?
|
|
1109
|
+
align_vertical(vertical) unless vertical.nil?
|
|
1110
|
+
wrap_text(wrap_text) unless wrap_text.nil?
|
|
1111
|
+
text_rotation(text_rotation) unless text_rotation.nil?
|
|
1112
|
+
indent(indent) unless indent.nil?
|
|
1113
|
+
shrink_to_fit(shrink_to_fit) unless shrink_to_fit.nil?
|
|
1114
|
+
@alignment[:reading_order] = reading_order unless reading_order.nil?
|
|
1115
|
+
@alignment[:justify_last_line] = justify_last_line unless justify_last_line.nil?
|
|
1116
|
+
@alignment[:relative_indent] = relative_indent unless relative_indent.nil?
|
|
1117
|
+
self
|
|
1118
|
+
end
|
|
1119
|
+
|
|
1120
|
+
# Sets alignment options.
|
|
1121
|
+
#
|
|
1122
|
+
# @param opts [Hash]
|
|
1123
|
+
# @return [Hash]
|
|
1124
|
+
# @api public
|
|
1125
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
1126
|
+
def alignment=(opts)
|
|
1127
|
+
alignment(**opts)
|
|
1128
|
+
opts
|
|
1129
|
+
end
|
|
1130
|
+
|
|
1131
|
+
# Gets or sets horizontal alignment.
|
|
1132
|
+
# @param value [String, Symbol, Object] The alignment.
|
|
1133
|
+
# @return [String, Symbol, self, nil]
|
|
1134
|
+
# @api public
|
|
1135
|
+
#: (?untyped value) -> (String | Symbol | self | nil)
|
|
1136
|
+
def align_horizontal(value = OMITTED)
|
|
1137
|
+
return @alignment[:horizontal] if value.equal?(OMITTED)
|
|
1138
|
+
|
|
1139
|
+
@alignment[:horizontal] = value
|
|
1140
|
+
self
|
|
1141
|
+
end
|
|
1142
|
+
|
|
733
1143
|
# Sets horizontal alignment.
|
|
734
|
-
# @param value [String, Symbol]
|
|
735
|
-
# @return [
|
|
1144
|
+
# @param value [String, Symbol]
|
|
1145
|
+
# @return [String, Symbol]
|
|
736
1146
|
# @api public
|
|
737
|
-
#: (String | Symbol) ->
|
|
738
|
-
def align_horizontal(value)
|
|
1147
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1148
|
+
def align_horizontal=(value)
|
|
739
1149
|
@alignment[:horizontal] = value
|
|
1150
|
+
end
|
|
1151
|
+
|
|
1152
|
+
# Gets or sets vertical alignment.
|
|
1153
|
+
# @param value [String, Symbol, Object] The alignment.
|
|
1154
|
+
# @return [String, Symbol, self, nil]
|
|
1155
|
+
# @api public
|
|
1156
|
+
#: (?untyped value) -> (String | Symbol | self | nil)
|
|
1157
|
+
def align_vertical(value = OMITTED)
|
|
1158
|
+
return @alignment[:vertical] if value.equal?(OMITTED)
|
|
1159
|
+
|
|
1160
|
+
@alignment[:vertical] = value
|
|
740
1161
|
self
|
|
741
1162
|
end
|
|
742
1163
|
|
|
743
1164
|
# Sets vertical alignment.
|
|
744
|
-
# @param value [String, Symbol]
|
|
745
|
-
# @return [
|
|
1165
|
+
# @param value [String, Symbol]
|
|
1166
|
+
# @return [String, Symbol]
|
|
746
1167
|
# @api public
|
|
747
|
-
#: (String | Symbol) ->
|
|
748
|
-
def align_vertical(value)
|
|
1168
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1169
|
+
def align_vertical=(value)
|
|
749
1170
|
@alignment[:vertical] = value
|
|
750
|
-
self
|
|
751
1171
|
end
|
|
752
1172
|
|
|
753
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
|
754
1173
|
# Sets text wrapping.
|
|
755
1174
|
# @param value [Boolean] Whether to wrap text.
|
|
756
1175
|
# @return [self]
|
|
757
1176
|
# @api public
|
|
758
|
-
#: (?
|
|
759
|
-
def wrap_text(value =
|
|
760
|
-
|
|
1177
|
+
#: (?untyped) -> (self | bool)
|
|
1178
|
+
def wrap_text(value = OMITTED)
|
|
1179
|
+
if value.equal?(OMITTED)
|
|
1180
|
+
return wrap_text? unless @alignment[:wrap_text].nil?
|
|
1181
|
+
|
|
1182
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#wrap_text with zero arguments as a mutator is deprecated; pass true explicitly (e.g. wrap_text(true))", uplevel: 1)
|
|
1183
|
+
@alignment[:wrap_text] = true
|
|
1184
|
+
return self
|
|
1185
|
+
end
|
|
1186
|
+
|
|
1187
|
+
@alignment[:wrap_text] = value ? true : false
|
|
761
1188
|
self
|
|
762
1189
|
end
|
|
763
1190
|
|
|
1191
|
+
# Sets text wrapping.
|
|
1192
|
+
# @param value [Boolean]
|
|
1193
|
+
# @return [Boolean]
|
|
1194
|
+
# @api public
|
|
1195
|
+
#: (bool value) -> bool
|
|
1196
|
+
def wrap_text=(value)
|
|
1197
|
+
@alignment[:wrap_text] = value
|
|
1198
|
+
end
|
|
1199
|
+
|
|
1200
|
+
# Returns whether text wrapping is enabled.
|
|
1201
|
+
# @return [Boolean]
|
|
1202
|
+
# @api public
|
|
1203
|
+
#: () -> bool
|
|
1204
|
+
def wrap_text?
|
|
1205
|
+
@alignment[:wrap_text] ? true : false
|
|
1206
|
+
end
|
|
1207
|
+
|
|
764
1208
|
# Sets shrink to fit.
|
|
765
1209
|
# @param value [Boolean] Whether to shrink text.
|
|
766
1210
|
# @return [self]
|
|
767
1211
|
# @api public
|
|
768
|
-
#: (?
|
|
769
|
-
def shrink_to_fit(value =
|
|
1212
|
+
#: (?untyped) -> (self | bool)
|
|
1213
|
+
def shrink_to_fit(value = OMITTED)
|
|
1214
|
+
if value.equal?(OMITTED)
|
|
1215
|
+
return shrink_to_fit? unless @alignment[:shrink_to_fit].nil?
|
|
1216
|
+
|
|
1217
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#shrink_to_fit with zero arguments as a mutator is deprecated; pass true explicitly (e.g. shrink_to_fit(true))", uplevel: 1)
|
|
1218
|
+
@alignment[:shrink_to_fit] = true
|
|
1219
|
+
return self
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
@alignment[:shrink_to_fit] = value ? true : false
|
|
1223
|
+
self
|
|
1224
|
+
end
|
|
1225
|
+
|
|
1226
|
+
# Sets shrink to fit.
|
|
1227
|
+
# @param value [Boolean]
|
|
1228
|
+
# @return [Boolean]
|
|
1229
|
+
# @api public
|
|
1230
|
+
#: (bool value) -> bool
|
|
1231
|
+
def shrink_to_fit=(value)
|
|
770
1232
|
@alignment[:shrink_to_fit] = value
|
|
1233
|
+
end
|
|
1234
|
+
|
|
1235
|
+
# Returns whether shrink to fit is enabled.
|
|
1236
|
+
# @return [Boolean]
|
|
1237
|
+
# @api public
|
|
1238
|
+
#: () -> bool
|
|
1239
|
+
def shrink_to_fit?
|
|
1240
|
+
@alignment[:shrink_to_fit] ? true : false
|
|
1241
|
+
end
|
|
1242
|
+
|
|
1243
|
+
# Gets or sets text rotation.
|
|
1244
|
+
# @param value [Numeric, Object] The rotation angle.
|
|
1245
|
+
# @return [Numeric, self, nil]
|
|
1246
|
+
# @api public
|
|
1247
|
+
#: (?untyped value) -> (Numeric | self | nil)
|
|
1248
|
+
def text_rotation(value = OMITTED)
|
|
1249
|
+
return @alignment[:text_rotation] if value.equal?(OMITTED)
|
|
1250
|
+
|
|
1251
|
+
@alignment[:text_rotation] = value
|
|
771
1252
|
self
|
|
772
1253
|
end
|
|
773
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
774
1254
|
|
|
775
1255
|
# Sets text rotation.
|
|
776
|
-
# @param value [Numeric]
|
|
777
|
-
# @return [
|
|
1256
|
+
# @param value [Numeric]
|
|
1257
|
+
# @return [Numeric]
|
|
778
1258
|
# @api public
|
|
779
|
-
#: (Numeric) ->
|
|
780
|
-
def text_rotation(value)
|
|
1259
|
+
#: (Numeric value) -> Numeric
|
|
1260
|
+
def text_rotation=(value)
|
|
781
1261
|
@alignment[:text_rotation] = value
|
|
1262
|
+
end
|
|
1263
|
+
|
|
1264
|
+
# Gets or sets text indent.
|
|
1265
|
+
# @param value [Numeric, Object] The indent level.
|
|
1266
|
+
# @return [Numeric, self, nil]
|
|
1267
|
+
# @api public
|
|
1268
|
+
#: (?untyped value) -> (Numeric | self | nil)
|
|
1269
|
+
def indent(value = OMITTED)
|
|
1270
|
+
return @alignment[:indent] if value.equal?(OMITTED)
|
|
1271
|
+
|
|
1272
|
+
@alignment[:indent] = value.to_i
|
|
782
1273
|
self
|
|
783
1274
|
end
|
|
784
1275
|
|
|
785
1276
|
# Sets text indent.
|
|
786
|
-
# @param value [Numeric]
|
|
787
|
-
# @return [
|
|
1277
|
+
# @param value [Numeric]
|
|
1278
|
+
# @return [Numeric]
|
|
788
1279
|
# @api public
|
|
789
|
-
#: (Numeric) ->
|
|
790
|
-
def indent(value)
|
|
1280
|
+
#: (Numeric value) -> Numeric
|
|
1281
|
+
def indent=(value)
|
|
791
1282
|
@alignment[:indent] = value.to_i
|
|
1283
|
+
end
|
|
1284
|
+
|
|
1285
|
+
# --- Protection Properties ---
|
|
1286
|
+
|
|
1287
|
+
# Configures or returns cell protection properties.
|
|
1288
|
+
# When called with 0 arguments/keywords, returns the current protection Hash.
|
|
1289
|
+
# When called with keyword arguments, merges the properties and returns self.
|
|
1290
|
+
#
|
|
1291
|
+
# @param locked [Boolean, nil]
|
|
1292
|
+
# @param hidden [Boolean, nil]
|
|
1293
|
+
# @return [Hash, self]
|
|
1294
|
+
# @api public
|
|
1295
|
+
#: (?locked: bool?, ?hidden: bool?) -> (Hash[Symbol, untyped] | self)
|
|
1296
|
+
def protection(locked: nil, hidden: nil)
|
|
1297
|
+
return @protection if locked.nil? && hidden.nil?
|
|
1298
|
+
|
|
1299
|
+
@protection[:locked] = locked unless locked.nil?
|
|
1300
|
+
@protection[:hidden] = hidden unless hidden.nil?
|
|
1301
|
+
self
|
|
1302
|
+
end
|
|
1303
|
+
|
|
1304
|
+
# Sets protection options.
|
|
1305
|
+
#
|
|
1306
|
+
# @param opts [Hash]
|
|
1307
|
+
# @return [Hash]
|
|
1308
|
+
# @api public
|
|
1309
|
+
#: (Hash[Symbol, untyped] opts) -> Hash[Symbol, untyped]
|
|
1310
|
+
def protection=(opts)
|
|
1311
|
+
protection(**opts)
|
|
1312
|
+
opts
|
|
1313
|
+
end
|
|
1314
|
+
|
|
1315
|
+
# Sets whether the cell is locked.
|
|
1316
|
+
#
|
|
1317
|
+
# @param value [Boolean]
|
|
1318
|
+
# @return [self]
|
|
1319
|
+
# @api public
|
|
1320
|
+
#: (?untyped value) -> (self | bool)
|
|
1321
|
+
def locked(value = OMITTED)
|
|
1322
|
+
if value.equal?(OMITTED)
|
|
1323
|
+
return locked? unless @protection[:locked].nil?
|
|
1324
|
+
|
|
1325
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#locked with zero arguments as a mutator is deprecated; pass true explicitly (e.g. locked(true))", uplevel: 1)
|
|
1326
|
+
@protection[:locked] = true
|
|
1327
|
+
return self
|
|
1328
|
+
end
|
|
1329
|
+
|
|
1330
|
+
@protection[:locked] = value ? true : false
|
|
792
1331
|
self
|
|
793
1332
|
end
|
|
794
1333
|
|
|
1334
|
+
# Sets whether the cell is locked.
|
|
1335
|
+
#
|
|
1336
|
+
# @param value [Boolean]
|
|
1337
|
+
# @return [Boolean]
|
|
1338
|
+
# @api public
|
|
1339
|
+
#: (bool value) -> bool
|
|
1340
|
+
def locked=(value)
|
|
1341
|
+
@protection[:locked] = value
|
|
1342
|
+
end
|
|
1343
|
+
|
|
1344
|
+
# Returns whether the cell is locked.
|
|
1345
|
+
# @return [Boolean]
|
|
1346
|
+
# @api public
|
|
1347
|
+
#: () -> bool
|
|
1348
|
+
def locked?
|
|
1349
|
+
@protection[:locked] != false
|
|
1350
|
+
end
|
|
1351
|
+
|
|
1352
|
+
# Sets whether the cell formula is hidden.
|
|
1353
|
+
#
|
|
1354
|
+
# @param value [Boolean]
|
|
1355
|
+
# @return [self]
|
|
1356
|
+
# @api public
|
|
1357
|
+
#: (?untyped value) -> (self | bool)
|
|
1358
|
+
def hidden(value = OMITTED)
|
|
1359
|
+
if value.equal?(OMITTED)
|
|
1360
|
+
return hidden? unless @protection[:hidden].nil?
|
|
1361
|
+
|
|
1362
|
+
Xlsxrb::Deprecation.warn("Calling StyleBuilder#hidden with zero arguments as a mutator is deprecated; pass true explicitly (e.g. hidden(true))", uplevel: 1)
|
|
1363
|
+
@protection[:hidden] = true
|
|
1364
|
+
return self
|
|
1365
|
+
end
|
|
1366
|
+
|
|
1367
|
+
@protection[:hidden] = value ? true : false
|
|
1368
|
+
self
|
|
1369
|
+
end
|
|
1370
|
+
|
|
1371
|
+
# Sets whether the cell formula is hidden.
|
|
1372
|
+
#
|
|
1373
|
+
# @param value [Boolean]
|
|
1374
|
+
# @return [Boolean]
|
|
1375
|
+
# @api public
|
|
1376
|
+
#: (bool value) -> bool
|
|
1377
|
+
def hidden=(value)
|
|
1378
|
+
@protection[:hidden] = value
|
|
1379
|
+
end
|
|
1380
|
+
|
|
1381
|
+
# Returns whether the cell formula is hidden.
|
|
1382
|
+
# @return [Boolean]
|
|
1383
|
+
# @api public
|
|
1384
|
+
#: () -> bool
|
|
1385
|
+
def hidden?
|
|
1386
|
+
@protection[:hidden] ? true : false
|
|
1387
|
+
end
|
|
1388
|
+
|
|
795
1389
|
# --- Number Format ---
|
|
796
1390
|
|
|
1391
|
+
# Sets or gets the number format.
|
|
1392
|
+
# @param num_fmt_id [String, Integer, nil] The format id or format string.
|
|
1393
|
+
# @return [String, Integer, self, nil]
|
|
1394
|
+
# @api public
|
|
1395
|
+
#: (?String | Integer | nil num_fmt_id) -> (String | Integer | self | nil)
|
|
1396
|
+
def number_format(num_fmt_id = nil)
|
|
1397
|
+
if num_fmt_id.nil?
|
|
1398
|
+
@num_fmt_id
|
|
1399
|
+
else
|
|
1400
|
+
@num_fmt_id = num_fmt_id
|
|
1401
|
+
self
|
|
1402
|
+
end
|
|
1403
|
+
end
|
|
1404
|
+
|
|
797
1405
|
# Sets the number format.
|
|
798
|
-
# @param num_fmt_id [String, Integer]
|
|
799
|
-
# @return [
|
|
1406
|
+
# @param num_fmt_id [String, Integer]
|
|
1407
|
+
# @return [String, Integer]
|
|
800
1408
|
# @api public
|
|
801
|
-
#: (String | Integer) ->
|
|
802
|
-
def number_format(num_fmt_id)
|
|
1409
|
+
#: (String | Integer num_fmt_id) -> (String | Integer)
|
|
1410
|
+
def number_format=(num_fmt_id)
|
|
803
1411
|
@num_fmt_id = num_fmt_id
|
|
804
|
-
self
|
|
805
1412
|
end
|
|
806
|
-
|
|
1413
|
+
|
|
1414
|
+
# Sets or gets the number format ID.
|
|
1415
|
+
# @deprecated Use {#number_format} instead. Will be removed in 0.2.0.
|
|
1416
|
+
# @param id [String, Integer, nil]
|
|
1417
|
+
# @return [String, Integer, self, nil]
|
|
1418
|
+
# @api public
|
|
1419
|
+
#: (?String | Integer | nil id) -> (String | Integer | self | nil)
|
|
1420
|
+
def number_format_id(id = nil)
|
|
1421
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder#number_format_id is deprecated; use #number_format instead.", uplevel: 1
|
|
1422
|
+
number_format(id)
|
|
1423
|
+
end
|
|
1424
|
+
|
|
1425
|
+
# Sets the number format ID.
|
|
1426
|
+
# @deprecated Use {#number_format=} instead. Will be removed in 0.2.0.
|
|
1427
|
+
# @param id [String, Integer]
|
|
1428
|
+
# @return [String, Integer]
|
|
1429
|
+
# @api public
|
|
1430
|
+
#: (String | Integer id) -> (String | Integer)
|
|
1431
|
+
def number_format_id=(id)
|
|
1432
|
+
warn "[Xlsxrb DEPRECATION] StyleBuilder#number_format_id= is deprecated; use #number_format= instead.", uplevel: 1
|
|
1433
|
+
@num_fmt_id = id
|
|
1434
|
+
end
|
|
1435
|
+
|
|
1436
|
+
# @deprecated Use {#number_format} instead. Will be removed in 0.2.0.
|
|
1437
|
+
#: (?String | Integer | nil num_fmt_id) -> (String | Integer | self | nil)
|
|
1438
|
+
def num_fmt(num_fmt_id = nil)
|
|
1439
|
+
warn "[DEPRECATION] #num_fmt is deprecated; use #number_format instead.", uplevel: 1
|
|
1440
|
+
number_format(num_fmt_id)
|
|
1441
|
+
end
|
|
1442
|
+
|
|
1443
|
+
# @deprecated Use {#number_format=} instead. Will be removed in 0.2.0.
|
|
1444
|
+
#: (String | Integer num_fmt_id) -> (String | Integer)
|
|
1445
|
+
def num_fmt=(num_fmt_id)
|
|
1446
|
+
warn "[DEPRECATION] #num_fmt= is deprecated; use #number_format= instead.", uplevel: 1
|
|
1447
|
+
self.number_format = num_fmt_id
|
|
1448
|
+
end
|
|
1449
|
+
|
|
1450
|
+
# @deprecated Use {#number_format_id} instead. Will be removed in 0.2.0.
|
|
1451
|
+
#: (?String | Integer | nil id) -> (String | Integer | self | nil)
|
|
1452
|
+
def num_fmt_id(id = nil)
|
|
1453
|
+
warn "[DEPRECATION] #num_fmt_id is deprecated; use #number_format_id instead.", uplevel: 1
|
|
1454
|
+
number_format_id(id)
|
|
1455
|
+
end
|
|
1456
|
+
|
|
1457
|
+
# @deprecated Use {#number_format_id=} instead. Will be removed in 0.2.0.
|
|
1458
|
+
#: (String | Integer id) -> (String | Integer)
|
|
1459
|
+
def num_fmt_id=(id)
|
|
1460
|
+
warn "[DEPRECATION] #num_fmt_id= is deprecated; use #number_format_id= instead.", uplevel: 1
|
|
1461
|
+
self.number_format_id = id
|
|
1462
|
+
end
|
|
807
1463
|
|
|
808
1464
|
# Register this style with the given Writer, returning the style_id.
|
|
809
1465
|
# writer:: Xlsxrb::Ooxml::Writer instance
|
|
@@ -830,8 +1486,15 @@ module Xlsxrb
|
|
|
830
1486
|
border_id: border_id
|
|
831
1487
|
}
|
|
832
1488
|
cell_style_opts[:alignment] = @alignment if @alignment.any?
|
|
1489
|
+
cell_style_opts[:protection] = @protection if @protection.any?
|
|
833
1490
|
|
|
834
1491
|
writer.add_cell_style(**cell_style_opts)
|
|
835
1492
|
end
|
|
1493
|
+
|
|
1494
|
+
private
|
|
1495
|
+
|
|
1496
|
+
def resolve_color(color)
|
|
1497
|
+
self.class.resolve_color(color)
|
|
1498
|
+
end
|
|
836
1499
|
end
|
|
837
1500
|
end
|