xlsxrb 0.1.16 → 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 +157 -1
- data/README.md +81 -21
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
- data/lib/xlsxrb/chart_builder.rb +619 -98
- data/lib/xlsxrb/dsl_helpers.rb +583 -15
- data/lib/xlsxrb/elements/cell.rb +265 -53
- data/lib/xlsxrb/elements/column.rb +95 -6
- 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 +243 -7
- data/lib/xlsxrb/elements/workbook.rb +202 -65
- data/lib/xlsxrb/elements/worksheet.rb +728 -85
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
- data/lib/xlsxrb/ooxml/reader.rb +92 -0
- data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
- data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
- data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
- data/lib/xlsxrb/ooxml/writer.rb +288 -35
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
- data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
- data/lib/xlsxrb/stream_row.rb +97 -18
- data/lib/xlsxrb/stream_sheet.rb +827 -157
- data/lib/xlsxrb/stream_writer.rb +2766 -375
- data/lib/xlsxrb/style_builder.rb +821 -105
- data/lib/xlsxrb/utils.rb +82 -57
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +542 -62
- data/lib/xlsxrb/worksheet_builder.rb +2279 -209
- data/lib/xlsxrb.rb +1539 -344
- data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
- data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
- data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
- data/sig/generated/xlsxrb/elements/column.rbs +62 -3
- 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 +29 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
- data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
- data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
- data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
- data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
- data/sig/generated/xlsxrb/stream_row.rbs +48 -14
- data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
- data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
- data/sig/generated/xlsxrb/style_builder.rbs +403 -75
- data/sig/generated/xlsxrb/utils.rbs +49 -13
- data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
- data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
- data/sig/generated/xlsxrb.rbs +321 -52
- metadata +3 -1
data/lib/xlsxrb/style_builder.rb
CHANGED
|
@@ -217,6 +217,24 @@ module Xlsxrb
|
|
|
217
217
|
13 => :slantDashDot
|
|
218
218
|
}.freeze
|
|
219
219
|
|
|
220
|
+
UNDERLINE_MAP = {
|
|
221
|
+
single: "single",
|
|
222
|
+
double: "double",
|
|
223
|
+
single_accounting: "singleAccounting",
|
|
224
|
+
double_accounting: "doubleAccounting",
|
|
225
|
+
none: "none"
|
|
226
|
+
}.freeze
|
|
227
|
+
|
|
228
|
+
VERT_ALIGN_MAP = {
|
|
229
|
+
superscript: "superscript",
|
|
230
|
+
super: "superscript",
|
|
231
|
+
subscript: "subscript",
|
|
232
|
+
sub: "subscript",
|
|
233
|
+
baseline: "baseline"
|
|
234
|
+
}.freeze
|
|
235
|
+
OMITTED = Object.new.freeze
|
|
236
|
+
private_constant :COLORS, :CSS_COLORS, :BORDER_STYLES, :BORDER_INDEX_MAP, :OMITTED
|
|
237
|
+
|
|
220
238
|
# Normalizes a color definition (CSS color name, hex code, or RGB integer) to an OpenXML hex color string.
|
|
221
239
|
#
|
|
222
240
|
# @example
|
|
@@ -229,7 +247,7 @@ module Xlsxrb
|
|
|
229
247
|
# @param color [String, Symbol, Integer, nil]
|
|
230
248
|
# @param alpha [Boolean] Whether to include the alpha channel ("AARRGGBB" vs "RRGGBB").
|
|
231
249
|
# @return [String, nil]
|
|
232
|
-
# @api
|
|
250
|
+
# @api private
|
|
233
251
|
#: (String | Symbol | Integer | nil color, ?alpha: bool) -> String?
|
|
234
252
|
def self.normalize_color(color, alpha: true)
|
|
235
253
|
return nil if color.nil?
|
|
@@ -283,7 +301,7 @@ module Xlsxrb
|
|
|
283
301
|
#
|
|
284
302
|
# @param style [Symbol, String, Integer, nil]
|
|
285
303
|
# @return [Symbol, nil]
|
|
286
|
-
# @api
|
|
304
|
+
# @api private
|
|
287
305
|
#: (Symbol | String | Integer | nil style) -> Symbol?
|
|
288
306
|
def self.normalize_border_style(style)
|
|
289
307
|
return nil if style.nil?
|
|
@@ -315,10 +333,6 @@ module Xlsxrb
|
|
|
315
333
|
color.to_s
|
|
316
334
|
end
|
|
317
335
|
|
|
318
|
-
def resolve_color(color)
|
|
319
|
-
self.class.resolve_color(color)
|
|
320
|
-
end
|
|
321
|
-
|
|
322
336
|
#: (?String? name) -> void
|
|
323
337
|
def initialize(name = nil)
|
|
324
338
|
@name = name
|
|
@@ -327,9 +341,23 @@ module Xlsxrb
|
|
|
327
341
|
@border_props = {}
|
|
328
342
|
@num_fmt_id = nil
|
|
329
343
|
@alignment = {}
|
|
344
|
+
@protection = {}
|
|
330
345
|
end
|
|
331
346
|
|
|
332
|
-
|
|
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
|
|
333
361
|
|
|
334
362
|
# Applies option-style definitions so callers can use add_style(name, **opts)
|
|
335
363
|
# as an alternative to block-based fluent chaining.
|
|
@@ -344,21 +372,71 @@ module Xlsxrb
|
|
|
344
372
|
font_opts = opts[:font] || {}
|
|
345
373
|
bold(font_opts[:bold]) if font_opts.key?(:bold)
|
|
346
374
|
italic(font_opts[:italic]) if font_opts.key?(:italic)
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
|
350
396
|
underline(font_opts[:underline]) if font_opts.key?(:underline)
|
|
351
397
|
strike(font_opts[:strike]) if font_opts.key?(:strike)
|
|
352
|
-
|
|
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
|
|
404
|
+
superscript(font_opts[:superscript]) if font_opts.key?(:superscript)
|
|
405
|
+
subscript(font_opts[:subscript]) if font_opts.key?(:subscript)
|
|
353
406
|
else
|
|
354
407
|
bold(opts[:bold]) if opts.key?(:bold)
|
|
355
408
|
italic(opts[:italic]) if opts.key?(:italic)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
|
359
430
|
underline(opts[:underline]) if opts.key?(:underline)
|
|
360
431
|
strike(opts[:strike]) if opts.key?(:strike)
|
|
361
|
-
|
|
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
|
|
438
|
+
superscript(opts[:superscript]) if opts.key?(:superscript)
|
|
439
|
+
subscript(opts[:subscript]) if opts.key?(:subscript)
|
|
362
440
|
end
|
|
363
441
|
|
|
364
442
|
if opts.key?(:fill)
|
|
@@ -400,7 +478,12 @@ module Xlsxrb
|
|
|
400
478
|
border_bottom(**opts[:border_bottom]) if opts.key?(:border_bottom) && opts[:border_bottom]
|
|
401
479
|
end
|
|
402
480
|
|
|
403
|
-
|
|
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
|
|
404
487
|
|
|
405
488
|
if opts.key?(:alignment)
|
|
406
489
|
align_opts = opts[:alignment] || {}
|
|
@@ -419,6 +502,15 @@ module Xlsxrb
|
|
|
419
502
|
shrink_to_fit(opts[:shrink_to_fit]) if opts.key?(:shrink_to_fit)
|
|
420
503
|
end
|
|
421
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
|
+
|
|
422
514
|
self
|
|
423
515
|
end
|
|
424
516
|
|
|
@@ -428,101 +520,369 @@ module Xlsxrb
|
|
|
428
520
|
# @param opts [Hash] The font properties.
|
|
429
521
|
# @return [self]
|
|
430
522
|
# @api public
|
|
431
|
-
#: (**untyped) -> self
|
|
523
|
+
#: (**untyped) -> (self | Hash[Symbol, untyped])
|
|
432
524
|
def font(**opts)
|
|
525
|
+
return @font_props if opts.empty?
|
|
526
|
+
|
|
433
527
|
bold(opts[:bold]) if opts.key?(:bold)
|
|
434
528
|
italic(opts[:italic]) if opts.key?(:italic)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
|
438
550
|
underline(opts[:underline]) if opts.key?(:underline)
|
|
439
551
|
strike(opts[:strike]) if opts.key?(:strike)
|
|
440
|
-
|
|
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
|
|
558
|
+
superscript(opts[:superscript]) if opts.key?(:superscript)
|
|
559
|
+
subscript(opts[:subscript]) if opts.key?(:subscript)
|
|
441
560
|
self
|
|
442
561
|
end
|
|
443
562
|
|
|
444
|
-
|
|
563
|
+
def font=(opts)
|
|
564
|
+
font(**opts)
|
|
565
|
+
end
|
|
566
|
+
|
|
445
567
|
# Sets the font to bold.
|
|
446
568
|
# @param value [Boolean] Whether to apply bold.
|
|
447
569
|
# @return [self]
|
|
448
570
|
# @api public
|
|
449
|
-
#: (?
|
|
450
|
-
def bold(value =
|
|
451
|
-
|
|
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
|
|
452
582
|
self
|
|
453
583
|
end
|
|
454
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
|
+
|
|
455
602
|
# Sets the font to italic.
|
|
456
603
|
# @param value [Boolean] Whether to apply italic.
|
|
457
604
|
# @return [self]
|
|
458
605
|
# @api public
|
|
459
|
-
#: (?
|
|
460
|
-
def italic(value =
|
|
461
|
-
|
|
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
|
|
462
617
|
self
|
|
463
618
|
end
|
|
464
619
|
|
|
465
|
-
# Sets the font
|
|
466
|
-
# @param
|
|
467
|
-
# @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]
|
|
631
|
+
# @api public
|
|
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]
|
|
468
697
|
# @api public
|
|
469
|
-
#: (
|
|
470
|
-
def
|
|
471
|
-
@font_props[:
|
|
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
|
|
472
703
|
self
|
|
473
704
|
end
|
|
474
705
|
|
|
475
706
|
# Sets the font name.
|
|
476
|
-
# @param name [String]
|
|
477
|
-
# @return [
|
|
707
|
+
# @param name [String]
|
|
708
|
+
# @return [String]
|
|
478
709
|
# @api public
|
|
479
|
-
#: (String) ->
|
|
480
|
-
def font_name(name)
|
|
710
|
+
#: (String name) -> String
|
|
711
|
+
def font_name=(name)
|
|
481
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)
|
|
482
724
|
self
|
|
483
725
|
end
|
|
484
726
|
|
|
485
727
|
# Sets the font color.
|
|
486
|
-
# @param color [String, Symbol]
|
|
487
|
-
# @return [
|
|
728
|
+
# @param color [String, Symbol]
|
|
729
|
+
# @return [String, Symbol]
|
|
488
730
|
# @api public
|
|
489
|
-
#: (String | Symbol) ->
|
|
490
|
-
def font_color(color)
|
|
731
|
+
#: (String | Symbol color) -> (String | Symbol)
|
|
732
|
+
def font_color=(color)
|
|
491
733
|
@font_props[:color] = resolve_color(color)
|
|
492
|
-
|
|
734
|
+
color
|
|
493
735
|
end
|
|
494
736
|
|
|
495
737
|
# Sets the font underline style.
|
|
496
|
-
# @param val [String] The underline style (e.g., 'single').
|
|
738
|
+
# @param val [String, Symbol, Boolean] The underline style (e.g., 'single', :double, :single_accounting, :double_accounting).
|
|
497
739
|
# @return [self]
|
|
498
740
|
# @api public
|
|
499
|
-
#: (?
|
|
500
|
-
def underline(val =
|
|
501
|
-
|
|
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
|
+
|
|
751
|
+
mapped = if [true, "single"].include?(val)
|
|
752
|
+
"single"
|
|
753
|
+
elsif val == false
|
|
754
|
+
nil
|
|
755
|
+
else
|
|
756
|
+
UNDERLINE_MAP[val.to_sym] || val.to_s
|
|
757
|
+
end
|
|
758
|
+
@font_props[:underline] = mapped
|
|
502
759
|
self
|
|
503
760
|
end
|
|
504
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
|
+
|
|
505
780
|
# Sets the font strikethrough.
|
|
506
781
|
# @param value [Boolean] Whether to apply strike.
|
|
507
782
|
# @return [self]
|
|
508
783
|
# @api public
|
|
509
|
-
#: (?
|
|
510
|
-
def strike(value =
|
|
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
|
|
795
|
+
self
|
|
796
|
+
end
|
|
797
|
+
|
|
798
|
+
# Sets the font strikethrough.
|
|
799
|
+
# @param value [Boolean]
|
|
800
|
+
# @return [Boolean]
|
|
801
|
+
# @api public
|
|
802
|
+
#: (bool value) -> bool
|
|
803
|
+
def strike=(value)
|
|
511
804
|
@font_props[:strike] = value
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
# Returns whether strikethrough is enabled.
|
|
808
|
+
# @return [Boolean]
|
|
809
|
+
# @api public
|
|
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
|
+
|
|
823
|
+
mapped = VERT_ALIGN_MAP[value.to_sym] || value.to_s
|
|
824
|
+
@font_props[:vert_align] = mapped
|
|
512
825
|
self
|
|
513
826
|
end
|
|
514
827
|
|
|
515
|
-
|
|
516
|
-
|
|
828
|
+
def vert_align=(value)
|
|
829
|
+
vert_align(value)
|
|
830
|
+
value
|
|
831
|
+
end
|
|
832
|
+
|
|
833
|
+
# Sets the font to superscript.
|
|
834
|
+
# @param value [Boolean] Whether to apply superscript.
|
|
517
835
|
# @return [self]
|
|
518
836
|
# @api public
|
|
519
|
-
#: (
|
|
520
|
-
def
|
|
521
|
-
|
|
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
|
+
|
|
847
|
+
@font_props[:vert_align] = value ? "superscript" : "baseline"
|
|
522
848
|
self
|
|
523
849
|
end
|
|
524
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
525
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
|
+
|
|
860
|
+
# Sets the font to subscript.
|
|
861
|
+
# @param value [Boolean] Whether to apply subscript.
|
|
862
|
+
# @return [self]
|
|
863
|
+
# @api public
|
|
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
|
+
|
|
874
|
+
@font_props[:vert_align] = value ? "subscript" : "baseline"
|
|
875
|
+
self
|
|
876
|
+
end
|
|
877
|
+
|
|
878
|
+
def subscript=(value)
|
|
879
|
+
subscript(value)
|
|
880
|
+
value
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
def subscript?
|
|
884
|
+
@font_props[:vert_align] == "subscript"
|
|
885
|
+
end
|
|
526
886
|
# --- Fill Properties ---
|
|
527
887
|
|
|
528
888
|
# Sets the fill pattern.
|
|
@@ -537,28 +897,63 @@ module Xlsxrb
|
|
|
537
897
|
# @param bg_color [String, Symbol, nil] The background color.
|
|
538
898
|
# @return [self]
|
|
539
899
|
# @api public
|
|
540
|
-
#: (
|
|
541
|
-
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
|
+
|
|
542
904
|
@fill_props[:pattern] = pattern
|
|
543
905
|
@fill_props[:fg_color] = fg_color if fg_color
|
|
544
906
|
@fill_props[:bg_color] = bg_color if bg_color
|
|
545
907
|
self
|
|
546
908
|
end
|
|
547
909
|
|
|
548
|
-
# Sets
|
|
549
|
-
# @param
|
|
550
|
-
# @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]
|
|
551
927
|
# @api public
|
|
552
|
-
#: (String | Symbol
|
|
553
|
-
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
|
+
|
|
554
932
|
@fill_props[:pattern] = "solid"
|
|
555
933
|
@fill_props[:fg_color] = resolve_color(color)
|
|
556
934
|
self
|
|
557
935
|
end
|
|
558
936
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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)
|
|
562
957
|
end
|
|
563
958
|
|
|
564
959
|
# Sets a gradient fill.
|
|
@@ -567,8 +962,10 @@ module Xlsxrb
|
|
|
567
962
|
# @param stops [Array] The gradient stops.
|
|
568
963
|
# @return [self]
|
|
569
964
|
# @api public
|
|
570
|
-
#: (type:
|
|
571
|
-
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
|
+
|
|
572
969
|
@fill_props[:gradient] = {
|
|
573
970
|
type: type,
|
|
574
971
|
degree: degree,
|
|
@@ -580,19 +977,31 @@ module Xlsxrb
|
|
|
580
977
|
# --- Border Properties ---
|
|
581
978
|
|
|
582
979
|
# Configures multiple border properties.
|
|
583
|
-
# @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]
|
|
584
986
|
# @return [self]
|
|
585
987
|
# @api public
|
|
586
|
-
#: (
|
|
587
|
-
def border(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
|
593
998
|
self
|
|
594
999
|
end
|
|
595
1000
|
|
|
1001
|
+
def border=(opts)
|
|
1002
|
+
border(**opts)
|
|
1003
|
+
end
|
|
1004
|
+
|
|
596
1005
|
# Sets all borders.
|
|
597
1006
|
# @param style [String, Symbol, Integer] The border style.
|
|
598
1007
|
# @param color [String, Symbol, nil] The color.
|
|
@@ -677,80 +1086,380 @@ module Xlsxrb
|
|
|
677
1086
|
|
|
678
1087
|
# --- Alignment Properties ---
|
|
679
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
|
+
|
|
680
1143
|
# Sets horizontal alignment.
|
|
681
|
-
# @param value [String, Symbol]
|
|
682
|
-
# @return [
|
|
1144
|
+
# @param value [String, Symbol]
|
|
1145
|
+
# @return [String, Symbol]
|
|
683
1146
|
# @api public
|
|
684
|
-
#: (String | Symbol) ->
|
|
685
|
-
def align_horizontal(value)
|
|
1147
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1148
|
+
def align_horizontal=(value)
|
|
686
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
|
|
687
1161
|
self
|
|
688
1162
|
end
|
|
689
1163
|
|
|
690
1164
|
# Sets vertical alignment.
|
|
691
|
-
# @param value [String, Symbol]
|
|
692
|
-
# @return [
|
|
1165
|
+
# @param value [String, Symbol]
|
|
1166
|
+
# @return [String, Symbol]
|
|
693
1167
|
# @api public
|
|
694
|
-
#: (String | Symbol) ->
|
|
695
|
-
def align_vertical(value)
|
|
1168
|
+
#: (String | Symbol value) -> (String | Symbol)
|
|
1169
|
+
def align_vertical=(value)
|
|
696
1170
|
@alignment[:vertical] = value
|
|
697
|
-
self
|
|
698
1171
|
end
|
|
699
1172
|
|
|
700
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
|
701
1173
|
# Sets text wrapping.
|
|
702
1174
|
# @param value [Boolean] Whether to wrap text.
|
|
703
1175
|
# @return [self]
|
|
704
1176
|
# @api public
|
|
705
|
-
#: (?
|
|
706
|
-
def wrap_text(value =
|
|
707
|
-
|
|
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
|
|
708
1188
|
self
|
|
709
1189
|
end
|
|
710
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
|
+
|
|
711
1208
|
# Sets shrink to fit.
|
|
712
1209
|
# @param value [Boolean] Whether to shrink text.
|
|
713
1210
|
# @return [self]
|
|
714
1211
|
# @api public
|
|
715
|
-
#: (?
|
|
716
|
-
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)
|
|
717
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
|
|
718
1252
|
self
|
|
719
1253
|
end
|
|
720
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
|
721
1254
|
|
|
722
1255
|
# Sets text rotation.
|
|
723
|
-
# @param value [Numeric]
|
|
724
|
-
# @return [
|
|
1256
|
+
# @param value [Numeric]
|
|
1257
|
+
# @return [Numeric]
|
|
725
1258
|
# @api public
|
|
726
|
-
#: (Numeric) ->
|
|
727
|
-
def text_rotation(value)
|
|
1259
|
+
#: (Numeric value) -> Numeric
|
|
1260
|
+
def text_rotation=(value)
|
|
728
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
|
|
729
1273
|
self
|
|
730
1274
|
end
|
|
731
1275
|
|
|
732
1276
|
# Sets text indent.
|
|
733
|
-
# @param value [Numeric]
|
|
734
|
-
# @return [
|
|
1277
|
+
# @param value [Numeric]
|
|
1278
|
+
# @return [Numeric]
|
|
735
1279
|
# @api public
|
|
736
|
-
#: (Numeric) ->
|
|
737
|
-
def indent(value)
|
|
1280
|
+
#: (Numeric value) -> Numeric
|
|
1281
|
+
def indent=(value)
|
|
738
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
|
|
1331
|
+
self
|
|
1332
|
+
end
|
|
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
|
|
739
1368
|
self
|
|
740
1369
|
end
|
|
741
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
|
+
|
|
742
1389
|
# --- Number Format ---
|
|
743
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
|
+
|
|
744
1405
|
# Sets the number format.
|
|
745
|
-
# @param num_fmt_id [String, Integer]
|
|
746
|
-
# @return [
|
|
1406
|
+
# @param num_fmt_id [String, Integer]
|
|
1407
|
+
# @return [String, Integer]
|
|
747
1408
|
# @api public
|
|
748
|
-
#: (String | Integer) ->
|
|
749
|
-
def number_format(num_fmt_id)
|
|
1409
|
+
#: (String | Integer num_fmt_id) -> (String | Integer)
|
|
1410
|
+
def number_format=(num_fmt_id)
|
|
750
1411
|
@num_fmt_id = num_fmt_id
|
|
751
|
-
self
|
|
752
1412
|
end
|
|
753
|
-
|
|
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
|
|
754
1463
|
|
|
755
1464
|
# Register this style with the given Writer, returning the style_id.
|
|
756
1465
|
# writer:: Xlsxrb::Ooxml::Writer instance
|
|
@@ -777,8 +1486,15 @@ module Xlsxrb
|
|
|
777
1486
|
border_id: border_id
|
|
778
1487
|
}
|
|
779
1488
|
cell_style_opts[:alignment] = @alignment if @alignment.any?
|
|
1489
|
+
cell_style_opts[:protection] = @protection if @protection.any?
|
|
780
1490
|
|
|
781
1491
|
writer.add_cell_style(**cell_style_opts)
|
|
782
1492
|
end
|
|
1493
|
+
|
|
1494
|
+
private
|
|
1495
|
+
|
|
1496
|
+
def resolve_color(color)
|
|
1497
|
+
self.class.resolve_color(color)
|
|
1498
|
+
end
|
|
783
1499
|
end
|
|
784
1500
|
end
|