xlsxrb 0.2.0 → 0.2.1
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 +37 -0
- data/README.md +1 -1
- data/lib/xlsxrb/dsl_helpers.rb +49 -1
- data/lib/xlsxrb/elements/worksheet.rb +2 -2
- data/lib/xlsxrb/ooxml/utils.rb +13 -0
- data/lib/xlsxrb/ooxml/workbook_writer.rb +13 -2
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +302 -228
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +11 -4
- data/lib/xlsxrb/ooxml/writer.rb +1 -1
- data/lib/xlsxrb/ooxml/xml_builder.rb +18 -0
- data/lib/xlsxrb/stream_row.rb +2 -2
- data/lib/xlsxrb/stream_writer.rb +203 -80
- data/lib/xlsxrb/style_builder.rb +339 -0
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +239 -88
- data/lib/xlsxrb/worksheet_builder.rb +841 -134
- data/lib/xlsxrb.rb +19 -0
- data/sig/generated/xlsxrb/dsl_helpers.rbs +28 -0
- data/sig/generated/xlsxrb/ooxml/utils.rbs +10 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +5 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +53 -0
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +12 -0
- data/sig/generated/xlsxrb/stream_row.rbs +2 -2
- data/sig/generated/xlsxrb/stream_writer.rbs +40 -4
- data/sig/generated/xlsxrb/style_builder.rbs +261 -0
- data/sig/generated/xlsxrb/workbook_builder.rbs +42 -9
- data/sig/generated/xlsxrb/worksheet_builder.rbs +615 -3
- data/sig/generated/xlsxrb.rbs +15 -0
- metadata +1 -1
data/lib/xlsxrb/stream_writer.rb
CHANGED
|
@@ -84,6 +84,7 @@ module Xlsxrb
|
|
|
84
84
|
@sheet_entry_started = false
|
|
85
85
|
@current_row_writer = nil
|
|
86
86
|
@current_columns = []
|
|
87
|
+
@current_column_style_names = {} # column index => style name, for date style variants
|
|
87
88
|
@current_charts = []
|
|
88
89
|
@current_hyperlinks = []
|
|
89
90
|
@current_auto_filter = nil
|
|
@@ -127,6 +128,7 @@ module Xlsxrb
|
|
|
127
128
|
@styles = {} # { style_name => StyleBuilder }
|
|
128
129
|
@style_writer = Ooxml::Writer.new(default_font: default_font)
|
|
129
130
|
@style_name_to_id = {}
|
|
131
|
+
@time_like_style_ids = {} # cell style id => style id for Time-like values, see time_like_style_id
|
|
130
132
|
style("__xlsxrb_date", number_format: DslHelpers::DATE_NUMBER_FORMAT)
|
|
131
133
|
style("__xlsxrb_time", number_format: DslHelpers::TIME_NUMBER_FORMAT)
|
|
132
134
|
# Workbook-level settings
|
|
@@ -212,6 +214,8 @@ module Xlsxrb
|
|
|
212
214
|
# @yield [style_builder]
|
|
213
215
|
# @yieldparam style_builder [Xlsxrb::StyleBuilder]
|
|
214
216
|
# @return [StyleBuilder]
|
|
217
|
+
# Using the returned value is deprecated and warns; in version 0.3.0, this method
|
|
218
|
+
# will return nil. Configure the style with options or in the block.
|
|
215
219
|
#: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
|
|
216
220
|
def style(name, **opts)
|
|
217
221
|
style_name = name.to_s
|
|
@@ -222,8 +226,14 @@ module Xlsxrb
|
|
|
222
226
|
|
|
223
227
|
# Register immediately with low-level style writer
|
|
224
228
|
@style_name_to_id[style_name] = style_builder.register_with(@style_writer)
|
|
229
|
+
# Date and time variants of an earlier definition do not apply to this one.
|
|
230
|
+
@style_name_to_id.delete("#{style_name}__xlsxrb_date")
|
|
231
|
+
@style_name_to_id.delete("#{style_name}__xlsxrb_time")
|
|
232
|
+
# Column styles of the current sheet that use this name resolve to the new id.
|
|
233
|
+
@current_row_writer&.forget_column_style_ids
|
|
234
|
+
@time_like_style_ids.clear
|
|
225
235
|
|
|
226
|
-
style_builder
|
|
236
|
+
ReturnedStyleBuilder.new(style_builder)
|
|
227
237
|
end
|
|
228
238
|
|
|
229
239
|
# Sets or configures the workbook-wide default font.
|
|
@@ -341,7 +351,7 @@ module Xlsxrb
|
|
|
341
351
|
# @api public
|
|
342
352
|
#: (String | Symbol name, **untyped opts) ?{ (Xlsxrb::StyleBuilder) -> void } -> Xlsxrb::StyleBuilder
|
|
343
353
|
def style(...)
|
|
344
|
-
raise
|
|
354
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
345
355
|
|
|
346
356
|
@writer.style(...)
|
|
347
357
|
end
|
|
@@ -356,7 +366,7 @@ module Xlsxrb
|
|
|
356
366
|
# @api public
|
|
357
367
|
#: (String range) -> void
|
|
358
368
|
def merge(...)
|
|
359
|
-
raise
|
|
369
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
360
370
|
|
|
361
371
|
@writer.merge(...)
|
|
362
372
|
end
|
|
@@ -377,7 +387,7 @@ module Xlsxrb
|
|
|
377
387
|
# @api public
|
|
378
388
|
#: (?preset: String, ?text: String?, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
|
|
379
389
|
def shape(...)
|
|
380
|
-
raise
|
|
390
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
381
391
|
|
|
382
392
|
@writer.shape(...)
|
|
383
393
|
end
|
|
@@ -402,7 +412,7 @@ module Xlsxrb
|
|
|
402
412
|
# @api public
|
|
403
413
|
#: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
|
|
404
414
|
def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
|
|
405
|
-
raise
|
|
415
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
406
416
|
|
|
407
417
|
@writer.row(values, cell_styles: cell_styles, row_style: row_style, height: height, hidden: hidden, custom_height: custom_height, collapsed: collapsed, outline_level: outline_level)
|
|
408
418
|
end
|
|
@@ -431,7 +441,7 @@ module Xlsxrb
|
|
|
431
441
|
# @api public
|
|
432
442
|
#: (?Integer count) -> void
|
|
433
443
|
def skip_rows(count = 1)
|
|
434
|
-
raise
|
|
444
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
435
445
|
|
|
436
446
|
@writer.skip_rows(count)
|
|
437
447
|
end
|
|
@@ -453,7 +463,7 @@ module Xlsxrb
|
|
|
453
463
|
# @api public
|
|
454
464
|
#: (Integer | String | Symbol | Range[Integer | String | Symbol] | Array[Integer | String | Symbol] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?, ?best_fit: bool) -> void
|
|
455
465
|
def column(...)
|
|
456
|
-
raise
|
|
466
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
457
467
|
|
|
458
468
|
@writer.column(...)
|
|
459
469
|
end
|
|
@@ -470,7 +480,7 @@ module Xlsxrb
|
|
|
470
480
|
# @api public
|
|
471
481
|
#: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?level: Integer, ?collapsed: bool, ?hidden: bool, ?width: Float | Integer | nil, ?style: untyped) -> void
|
|
472
482
|
def group_columns(...)
|
|
473
|
-
raise
|
|
483
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
474
484
|
|
|
475
485
|
@writer.group_columns(...)
|
|
476
486
|
end
|
|
@@ -486,7 +496,7 @@ module Xlsxrb
|
|
|
486
496
|
# @api public
|
|
487
497
|
#: (?untyped rows, ?level: Integer, ?collapsed: bool, ?hidden: bool) ?{ (self) -> void } -> void
|
|
488
498
|
def group_rows(rows = nil, level: 1, collapsed: false, hidden: false)
|
|
489
|
-
raise
|
|
499
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
490
500
|
|
|
491
501
|
if block_given?
|
|
492
502
|
@writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden) do
|
|
@@ -509,7 +519,7 @@ module Xlsxrb
|
|
|
509
519
|
#: () -> Hash[Symbol, untyped]
|
|
510
520
|
#: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
|
|
511
521
|
def outline_properties(...)
|
|
512
|
-
raise
|
|
522
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
513
523
|
|
|
514
524
|
@writer.outline_properties(...)
|
|
515
525
|
end
|
|
@@ -521,7 +531,7 @@ module Xlsxrb
|
|
|
521
531
|
# @api public
|
|
522
532
|
#: (Hash[Symbol, untyped] opts) -> void
|
|
523
533
|
def outline_properties=(opts)
|
|
524
|
-
raise
|
|
534
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
525
535
|
|
|
526
536
|
@writer.outline_properties = opts
|
|
527
537
|
end
|
|
@@ -542,7 +552,7 @@ module Xlsxrb
|
|
|
542
552
|
# @api public
|
|
543
553
|
#: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
|
|
544
554
|
def chart(...)
|
|
545
|
-
raise
|
|
555
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
546
556
|
|
|
547
557
|
@writer.chart(...)
|
|
548
558
|
end
|
|
@@ -564,7 +574,7 @@ module Xlsxrb
|
|
|
564
574
|
# @api public
|
|
565
575
|
#: (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
|
|
566
576
|
def hyperlink(...)
|
|
567
|
-
raise
|
|
577
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
568
578
|
|
|
569
579
|
@writer.hyperlink(...)
|
|
570
580
|
end
|
|
@@ -575,7 +585,7 @@ module Xlsxrb
|
|
|
575
585
|
# @api public
|
|
576
586
|
#: () -> String?
|
|
577
587
|
def auto_filter
|
|
578
|
-
raise
|
|
588
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
579
589
|
|
|
580
590
|
@writer.auto_filter
|
|
581
591
|
end
|
|
@@ -587,7 +597,7 @@ module Xlsxrb
|
|
|
587
597
|
# @api public
|
|
588
598
|
#: (String? range) -> String?
|
|
589
599
|
def auto_filter=(range)
|
|
590
|
-
raise
|
|
600
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
591
601
|
|
|
592
602
|
@writer.auto_filter = range
|
|
593
603
|
end
|
|
@@ -603,7 +613,7 @@ module Xlsxrb
|
|
|
603
613
|
# @api public
|
|
604
614
|
#: (Integer | String | Symbol col_id, (Hash[untyped, untyped] | Array[untyped]) filter) -> void
|
|
605
615
|
def filter_column(...)
|
|
606
|
-
raise
|
|
616
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
607
617
|
|
|
608
618
|
@writer.filter_column(...)
|
|
609
619
|
end
|
|
@@ -621,7 +631,7 @@ module Xlsxrb
|
|
|
621
631
|
#: () -> Elements::SortState?
|
|
622
632
|
#: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> void
|
|
623
633
|
def sort_state(...)
|
|
624
|
-
raise
|
|
634
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
625
635
|
|
|
626
636
|
@writer.sort_state(...)
|
|
627
637
|
end
|
|
@@ -633,7 +643,7 @@ module Xlsxrb
|
|
|
633
643
|
# @api public
|
|
634
644
|
#: (Elements::SortState | Hash[Symbol, untyped] | nil opts) -> void
|
|
635
645
|
def sort_state=(opts)
|
|
636
|
-
raise
|
|
646
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
637
647
|
|
|
638
648
|
@writer.sort_state = opts
|
|
639
649
|
end
|
|
@@ -657,7 +667,7 @@ module Xlsxrb
|
|
|
657
667
|
# @api public
|
|
658
668
|
#: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
|
|
659
669
|
def data_validation(...)
|
|
660
|
-
raise
|
|
670
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
661
671
|
|
|
662
672
|
@writer.data_validation(...)
|
|
663
673
|
end
|
|
@@ -681,7 +691,7 @@ module Xlsxrb
|
|
|
681
691
|
# @api public
|
|
682
692
|
#: (?String? sqref, ?type: String | Symbol, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> void
|
|
683
693
|
def conditional_format(sqref = nil, **opts, &)
|
|
684
|
-
raise
|
|
694
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
685
695
|
|
|
686
696
|
@writer.conditional_format(sqref, **opts, &)
|
|
687
697
|
end
|
|
@@ -708,7 +718,7 @@ module Xlsxrb
|
|
|
708
718
|
# @api public
|
|
709
719
|
#: (?String? ref, ?columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) ?{ (TableBuilder) -> void } -> void
|
|
710
720
|
def table(...)
|
|
711
|
-
raise
|
|
721
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
712
722
|
|
|
713
723
|
@writer.table(...)
|
|
714
724
|
end
|
|
@@ -726,7 +736,7 @@ module Xlsxrb
|
|
|
726
736
|
# @api public
|
|
727
737
|
#: (String | Integer cell, String text, ?author: String, ?visible: bool) -> void
|
|
728
738
|
def comment(...)
|
|
729
|
-
raise
|
|
739
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
730
740
|
|
|
731
741
|
@writer.comment(...)
|
|
732
742
|
end
|
|
@@ -741,7 +751,7 @@ module Xlsxrb
|
|
|
741
751
|
# @api public
|
|
742
752
|
#: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
|
|
743
753
|
def threaded_comment(...)
|
|
744
|
-
raise
|
|
754
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
745
755
|
|
|
746
756
|
@writer.threaded_comment(...)
|
|
747
757
|
end
|
|
@@ -761,7 +771,7 @@ module Xlsxrb
|
|
|
761
771
|
# @api public
|
|
762
772
|
#: (String source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?ref: String?, ?name: String?, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
|
|
763
773
|
def pivot_table(...)
|
|
764
|
-
raise
|
|
774
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
765
775
|
|
|
766
776
|
@writer.pivot_table(...)
|
|
767
777
|
end
|
|
@@ -778,7 +788,7 @@ module Xlsxrb
|
|
|
778
788
|
# @api public
|
|
779
789
|
#: (sparklines: Array[Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
|
|
780
790
|
def sparkline_group(...)
|
|
781
|
-
raise
|
|
791
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
782
792
|
|
|
783
793
|
@writer.sparkline_group(...)
|
|
784
794
|
end
|
|
@@ -801,7 +811,7 @@ module Xlsxrb
|
|
|
801
811
|
# @api public
|
|
802
812
|
#: (Symbol | String new_state) -> Symbol
|
|
803
813
|
def state=(new_state)
|
|
804
|
-
raise
|
|
814
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
805
815
|
|
|
806
816
|
@writer.state = new_state
|
|
807
817
|
@writer.state
|
|
@@ -823,7 +833,7 @@ module Xlsxrb
|
|
|
823
833
|
# @api public
|
|
824
834
|
#: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
|
|
825
835
|
def tab_color=(spec)
|
|
826
|
-
raise
|
|
836
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
827
837
|
|
|
828
838
|
@writer.tab_color = spec
|
|
829
839
|
end
|
|
@@ -836,7 +846,7 @@ module Xlsxrb
|
|
|
836
846
|
#: () -> Elements::SheetProperties
|
|
837
847
|
#: (**untyped opts) -> void
|
|
838
848
|
def sheet_properties(**opts)
|
|
839
|
-
raise
|
|
849
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
840
850
|
|
|
841
851
|
@writer.sheet_properties(**opts)
|
|
842
852
|
end
|
|
@@ -847,7 +857,7 @@ module Xlsxrb
|
|
|
847
857
|
# @api public
|
|
848
858
|
#: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
|
|
849
859
|
def sheet_properties=(opts)
|
|
850
|
-
raise
|
|
860
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
851
861
|
|
|
852
862
|
@writer.sheet_properties = opts
|
|
853
863
|
end
|
|
@@ -867,7 +877,7 @@ module Xlsxrb
|
|
|
867
877
|
# @api public
|
|
868
878
|
#: (String name, ?untyped value, ?hidden: bool, ?columns: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?scope: (String | Symbol)?) -> void
|
|
869
879
|
def defined_name(name, value = nil, hidden: false, columns: nil, rows: nil, range: nil, sheet: nil, scope: nil)
|
|
870
|
-
raise
|
|
880
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
871
881
|
|
|
872
882
|
ref_sheet = sheet || @sheet_name
|
|
873
883
|
local_sheet = if scope
|
|
@@ -894,7 +904,7 @@ module Xlsxrb
|
|
|
894
904
|
#: () -> Elements::FreezePane?
|
|
895
905
|
#: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
896
906
|
def freeze_pane(...)
|
|
897
|
-
raise
|
|
907
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
898
908
|
|
|
899
909
|
@writer.freeze_pane(...)
|
|
900
910
|
end
|
|
@@ -906,7 +916,7 @@ module Xlsxrb
|
|
|
906
916
|
# @api public
|
|
907
917
|
#: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
|
|
908
918
|
def freeze_pane=(opts)
|
|
909
|
-
raise
|
|
919
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
910
920
|
|
|
911
921
|
@writer.freeze_pane = opts
|
|
912
922
|
end
|
|
@@ -927,7 +937,7 @@ module Xlsxrb
|
|
|
927
937
|
# @api public
|
|
928
938
|
#: (String? range) -> String?
|
|
929
939
|
def print_area=(range)
|
|
930
|
-
raise
|
|
940
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
931
941
|
|
|
932
942
|
@writer.send(:set_print_area, range, sheet: @sheet_name)
|
|
933
943
|
end
|
|
@@ -944,7 +954,7 @@ module Xlsxrb
|
|
|
944
954
|
#: () -> Elements::PrintTitles?
|
|
945
955
|
#: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?) -> void
|
|
946
956
|
def print_titles(rows: nil, columns: nil)
|
|
947
|
-
raise
|
|
957
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
948
958
|
|
|
949
959
|
if rows.nil? && columns.nil?
|
|
950
960
|
@writer.print_titles(sheet: @sheet_name)
|
|
@@ -960,7 +970,7 @@ module Xlsxrb
|
|
|
960
970
|
# @api public
|
|
961
971
|
#: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
|
|
962
972
|
def print_titles=(opts)
|
|
963
|
-
raise
|
|
973
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
964
974
|
|
|
965
975
|
if opts.nil?
|
|
966
976
|
@writer.print_titles = nil
|
|
@@ -979,7 +989,7 @@ module Xlsxrb
|
|
|
979
989
|
# @api public
|
|
980
990
|
#: (Integer | String first, ?(Integer | String)? last) -> void
|
|
981
991
|
def repeat_rows(first, last = nil)
|
|
982
|
-
raise
|
|
992
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
983
993
|
|
|
984
994
|
@writer.repeat_rows(first, last, sheet: @sheet_name)
|
|
985
995
|
end
|
|
@@ -992,7 +1002,7 @@ module Xlsxrb
|
|
|
992
1002
|
# @api public
|
|
993
1003
|
#: (Integer | String first, ?(Integer | String)? last) -> void
|
|
994
1004
|
def repeat_columns(first, last = nil)
|
|
995
|
-
raise
|
|
1005
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
996
1006
|
|
|
997
1007
|
@writer.repeat_columns(first, last, sheet: @sheet_name)
|
|
998
1008
|
end
|
|
@@ -1013,7 +1023,7 @@ module Xlsxrb
|
|
|
1013
1023
|
#: () -> Elements::SplitPane?
|
|
1014
1024
|
#: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
1015
1025
|
def split_pane(...)
|
|
1016
|
-
raise
|
|
1026
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1017
1027
|
|
|
1018
1028
|
@writer.split_pane(...)
|
|
1019
1029
|
end
|
|
@@ -1025,7 +1035,7 @@ module Xlsxrb
|
|
|
1025
1035
|
# @api public
|
|
1026
1036
|
#: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
|
|
1027
1037
|
def split_pane=(opts)
|
|
1028
|
-
raise
|
|
1038
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1029
1039
|
|
|
1030
1040
|
@writer.split_pane = opts
|
|
1031
1041
|
end
|
|
@@ -1043,7 +1053,7 @@ module Xlsxrb
|
|
|
1043
1053
|
#: () -> (Elements::Selection | Array[Elements::Selection])?
|
|
1044
1054
|
#: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
|
|
1045
1055
|
def selection(...)
|
|
1046
|
-
raise
|
|
1056
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1047
1057
|
|
|
1048
1058
|
@writer.selection(...)
|
|
1049
1059
|
end
|
|
@@ -1055,7 +1065,7 @@ module Xlsxrb
|
|
|
1055
1065
|
# @api public
|
|
1056
1066
|
#: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
|
|
1057
1067
|
def selection=(opts)
|
|
1058
|
-
raise
|
|
1068
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1059
1069
|
|
|
1060
1070
|
@writer.selection = opts
|
|
1061
1071
|
end
|
|
@@ -1076,7 +1086,7 @@ module Xlsxrb
|
|
|
1076
1086
|
#: () -> Elements::PageMargins?
|
|
1077
1087
|
#: (?left: Float | nil, ?right: Float | nil, ?top: Float | nil, ?bottom: Float | nil, ?header: Float | nil, ?footer: Float | nil) -> void
|
|
1078
1088
|
def page_margins(...)
|
|
1079
|
-
raise
|
|
1089
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1080
1090
|
|
|
1081
1091
|
@writer.page_margins(...)
|
|
1082
1092
|
end
|
|
@@ -1088,7 +1098,7 @@ module Xlsxrb
|
|
|
1088
1098
|
# @api public
|
|
1089
1099
|
#: (Hash[Symbol, untyped] | Elements::PageMargins | nil opts) -> void
|
|
1090
1100
|
def page_margins=(opts)
|
|
1091
|
-
raise
|
|
1101
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1092
1102
|
|
|
1093
1103
|
@writer.page_margins = opts
|
|
1094
1104
|
end
|
|
@@ -1106,7 +1116,7 @@ module Xlsxrb
|
|
|
1106
1116
|
#: () -> Elements::PageSetup
|
|
1107
1117
|
#: (**untyped opts) -> void
|
|
1108
1118
|
def page_setup(...)
|
|
1109
|
-
raise
|
|
1119
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1110
1120
|
|
|
1111
1121
|
@writer.page_setup(...)
|
|
1112
1122
|
end
|
|
@@ -1118,7 +1128,7 @@ module Xlsxrb
|
|
|
1118
1128
|
# @api public
|
|
1119
1129
|
#: (Hash[Symbol, untyped] | Elements::PageSetup opts) -> void
|
|
1120
1130
|
def page_setup=(opts)
|
|
1121
|
-
raise
|
|
1131
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1122
1132
|
|
|
1123
1133
|
@writer.page_setup = opts
|
|
1124
1134
|
end
|
|
@@ -1134,7 +1144,7 @@ module Xlsxrb
|
|
|
1134
1144
|
#: () -> Elements::HeaderFooter
|
|
1135
1145
|
#: (**untyped opts) -> void
|
|
1136
1146
|
def header_footer(...)
|
|
1137
|
-
raise
|
|
1147
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1138
1148
|
|
|
1139
1149
|
@writer.header_footer(...)
|
|
1140
1150
|
end
|
|
@@ -1146,7 +1156,7 @@ module Xlsxrb
|
|
|
1146
1156
|
# @api public
|
|
1147
1157
|
#: (Hash[Symbol, untyped] | Elements::HeaderFooter opts) -> void
|
|
1148
1158
|
def header_footer=(opts)
|
|
1149
|
-
raise
|
|
1159
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1150
1160
|
|
|
1151
1161
|
@writer.header_footer = opts
|
|
1152
1162
|
end
|
|
@@ -1160,7 +1170,7 @@ module Xlsxrb
|
|
|
1160
1170
|
#: () -> Elements::PrintOptions
|
|
1161
1171
|
#: (**untyped opts) -> void
|
|
1162
1172
|
def print_options(**opts)
|
|
1163
|
-
raise
|
|
1173
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1164
1174
|
|
|
1165
1175
|
@writer.print_options(**opts)
|
|
1166
1176
|
end
|
|
@@ -1171,7 +1181,7 @@ module Xlsxrb
|
|
|
1171
1181
|
# @api public
|
|
1172
1182
|
#: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
|
|
1173
1183
|
def print_options=(opts)
|
|
1174
|
-
raise
|
|
1184
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1175
1185
|
|
|
1176
1186
|
@writer.print_options = opts
|
|
1177
1187
|
end
|
|
@@ -1187,7 +1197,7 @@ module Xlsxrb
|
|
|
1187
1197
|
#: () -> Elements::SheetProtection?
|
|
1188
1198
|
#: (**untyped opts) -> void
|
|
1189
1199
|
def sheet_protection(...)
|
|
1190
|
-
raise
|
|
1200
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1191
1201
|
|
|
1192
1202
|
@writer.sheet_protection(...)
|
|
1193
1203
|
end
|
|
@@ -1199,7 +1209,7 @@ module Xlsxrb
|
|
|
1199
1209
|
# @api public
|
|
1200
1210
|
#: (Elements::SheetProtection | Hash[Symbol, untyped] | bool | nil opts) -> void
|
|
1201
1211
|
def sheet_protection=(opts)
|
|
1202
|
-
raise
|
|
1212
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1203
1213
|
|
|
1204
1214
|
@writer.sheet_protection = opts
|
|
1205
1215
|
end
|
|
@@ -1210,7 +1220,7 @@ module Xlsxrb
|
|
|
1210
1220
|
# @api public
|
|
1211
1221
|
#: () -> Array[Elements::Column]
|
|
1212
1222
|
def columns
|
|
1213
|
-
raise
|
|
1223
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1214
1224
|
|
|
1215
1225
|
@writer.columns
|
|
1216
1226
|
end
|
|
@@ -1228,7 +1238,7 @@ module Xlsxrb
|
|
|
1228
1238
|
# @api public
|
|
1229
1239
|
#: (String file_data, ?ext: String, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
|
|
1230
1240
|
def image(...)
|
|
1231
|
-
raise
|
|
1241
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1232
1242
|
|
|
1233
1243
|
@writer.image(...)
|
|
1234
1244
|
end
|
|
@@ -1249,7 +1259,7 @@ module Xlsxrb
|
|
|
1249
1259
|
# @api public
|
|
1250
1260
|
#: (untyped val) -> untyped
|
|
1251
1261
|
def background_image=(val)
|
|
1252
|
-
raise
|
|
1262
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1253
1263
|
|
|
1254
1264
|
@writer.background_image = val
|
|
1255
1265
|
end
|
|
@@ -1262,7 +1272,7 @@ module Xlsxrb
|
|
|
1262
1272
|
#: () -> Elements::SheetView
|
|
1263
1273
|
#: (**untyped opts) -> void
|
|
1264
1274
|
def sheet_view(**opts)
|
|
1265
|
-
raise
|
|
1275
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1266
1276
|
|
|
1267
1277
|
@writer.sheet_view(**opts)
|
|
1268
1278
|
end
|
|
@@ -1273,7 +1283,7 @@ module Xlsxrb
|
|
|
1273
1283
|
# @api public
|
|
1274
1284
|
#: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
|
|
1275
1285
|
def sheet_view=(opts)
|
|
1276
|
-
raise
|
|
1286
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1277
1287
|
|
|
1278
1288
|
@writer.sheet_view = opts
|
|
1279
1289
|
end
|
|
@@ -1286,7 +1296,7 @@ module Xlsxrb
|
|
|
1286
1296
|
#: () -> Elements::SheetFormat
|
|
1287
1297
|
#: (**untyped opts) -> void
|
|
1288
1298
|
def sheet_format(**opts)
|
|
1289
|
-
raise
|
|
1299
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1290
1300
|
|
|
1291
1301
|
@writer.sheet_format(**opts)
|
|
1292
1302
|
end
|
|
@@ -1297,7 +1307,7 @@ module Xlsxrb
|
|
|
1297
1307
|
# @api public
|
|
1298
1308
|
#: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
|
|
1299
1309
|
def sheet_format=(opts)
|
|
1300
|
-
raise
|
|
1310
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1301
1311
|
|
|
1302
1312
|
@writer.sheet_format = opts
|
|
1303
1313
|
end
|
|
@@ -1311,7 +1321,7 @@ module Xlsxrb
|
|
|
1311
1321
|
# @api public
|
|
1312
1322
|
#: (Integer row_index) -> void
|
|
1313
1323
|
def row_break(...)
|
|
1314
|
-
raise
|
|
1324
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1315
1325
|
|
|
1316
1326
|
@writer.row_break(...)
|
|
1317
1327
|
end
|
|
@@ -1326,7 +1336,7 @@ module Xlsxrb
|
|
|
1326
1336
|
# @api public
|
|
1327
1337
|
#: (Integer | String | Symbol col) -> void
|
|
1328
1338
|
def column_break(...)
|
|
1329
|
-
raise
|
|
1339
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1330
1340
|
|
|
1331
1341
|
@writer.column_break(...)
|
|
1332
1342
|
end
|
|
@@ -1342,7 +1352,7 @@ module Xlsxrb
|
|
|
1342
1352
|
# @api public
|
|
1343
1353
|
#: (String name, String sqref, ?password: String?, **untyped opts) -> void
|
|
1344
1354
|
def protected_range(...)
|
|
1345
|
-
raise
|
|
1355
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1346
1356
|
|
|
1347
1357
|
@writer.protected_range(...)
|
|
1348
1358
|
end
|
|
@@ -1354,7 +1364,7 @@ module Xlsxrb
|
|
|
1354
1364
|
# @api public
|
|
1355
1365
|
#: (String ref) -> void
|
|
1356
1366
|
def cell_watch(...)
|
|
1357
|
-
raise
|
|
1367
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1358
1368
|
|
|
1359
1369
|
@writer.cell_watch(...)
|
|
1360
1370
|
end
|
|
@@ -1367,7 +1377,7 @@ module Xlsxrb
|
|
|
1367
1377
|
# @api public
|
|
1368
1378
|
#: (String sqref, ?eval_error: bool, ?two_digit_text_year: bool, ?number_stored_as_text: bool, ?formula: bool, ?formula_range: bool, ?unlocked_formula: bool, ?empty_cell_reference: bool, ?list_data_validation: bool, ?calculated_column: bool) -> void
|
|
1369
1379
|
def ignored_error(...)
|
|
1370
|
-
raise
|
|
1380
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1371
1381
|
|
|
1372
1382
|
@writer.ignored_error(...)
|
|
1373
1383
|
end
|
|
@@ -1397,7 +1407,7 @@ module Xlsxrb
|
|
|
1397
1407
|
# @api public
|
|
1398
1408
|
#: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
|
|
1399
1409
|
def phonetic_properties=(spec)
|
|
1400
|
-
raise
|
|
1410
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1401
1411
|
|
|
1402
1412
|
@writer.phonetic_properties = spec
|
|
1403
1413
|
end
|
|
@@ -1418,7 +1428,7 @@ module Xlsxrb
|
|
|
1418
1428
|
# @api public
|
|
1419
1429
|
#: (String | Symbol | nil val) -> String?
|
|
1420
1430
|
def code_name=(val)
|
|
1421
|
-
raise
|
|
1431
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1422
1432
|
|
|
1423
1433
|
@writer.code_name = val
|
|
1424
1434
|
end
|
|
@@ -1439,7 +1449,7 @@ module Xlsxrb
|
|
|
1439
1449
|
# @api public
|
|
1440
1450
|
#: (bool? enabled) -> bool??
|
|
1441
1451
|
def fit_to_page=(enabled)
|
|
1442
|
-
raise
|
|
1452
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1443
1453
|
|
|
1444
1454
|
@writer.fit_to_page = enabled
|
|
1445
1455
|
end
|
|
@@ -1460,10 +1470,21 @@ module Xlsxrb
|
|
|
1460
1470
|
# @api public
|
|
1461
1471
|
#: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
|
|
1462
1472
|
def sheet_calc_properties=(spec)
|
|
1463
|
-
raise
|
|
1473
|
+
raise inactive_sheet_error if @writer.current_sheet != @sheet_name
|
|
1464
1474
|
|
|
1465
1475
|
@writer.sheet_calc_properties = spec
|
|
1466
1476
|
end
|
|
1477
|
+
|
|
1478
|
+
private
|
|
1479
|
+
|
|
1480
|
+
# The error for writing through a proxy whose sheet is not the current sheet: an
|
|
1481
|
+
# earlier sheet, or a sheet that was never created.
|
|
1482
|
+
#: () -> Error
|
|
1483
|
+
def inactive_sheet_error
|
|
1484
|
+
return Error.new("Sheet '#{@sheet_name}' does not exist. Create it with sheet before writing to it.") unless @writer.sheet_names.include?(@sheet_name)
|
|
1485
|
+
|
|
1486
|
+
Error.new("Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet.")
|
|
1487
|
+
end
|
|
1467
1488
|
end
|
|
1468
1489
|
|
|
1469
1490
|
# Returns the list of worksheet names created in this workbook so far.
|
|
@@ -1492,7 +1513,7 @@ module Xlsxrb
|
|
|
1492
1513
|
def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, **opts)
|
|
1493
1514
|
sheet_count = @sheets.size + (@current_sheet ? 1 : 0)
|
|
1494
1515
|
name ||= "Sheet#{sheet_count + 1}"
|
|
1495
|
-
raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters (Excel limitation)" if @strict_excel_mode && name
|
|
1516
|
+
raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters, counted in UTF-16 code units as Excel does (Excel limitation)" if @strict_excel_mode && Ooxml::Utils.utf16_length(name) > 31
|
|
1496
1517
|
raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet.forbidden_name_chars)
|
|
1497
1518
|
raise ArgumentError, "Sheet name '#{name}' cannot start or end with an apostrophe (Excel limitation)" if @strict_excel_mode && (name.start_with?("'") || name.end_with?("'"))
|
|
1498
1519
|
raise ArgumentError, "Sheet name '#{name}' is reserved by Excel (Excel limitation)" if @strict_excel_mode && name.casecmp?("History")
|
|
@@ -1524,8 +1545,15 @@ module Xlsxrb
|
|
|
1524
1545
|
@current_sheet
|
|
1525
1546
|
end
|
|
1526
1547
|
|
|
1548
|
+
UNKNOWN_SHEET_MESSAGE = "Looking up a sheet that does not exist with StreamWriter#[] is deprecated; " \
|
|
1549
|
+
"create it with sheet. In version 0.3.0, this will raise ArgumentError."
|
|
1550
|
+
private_constant :UNKNOWN_SHEET_MESSAGE
|
|
1551
|
+
|
|
1527
1552
|
# Returns a WorksheetProxy for the current or named sheet.
|
|
1528
1553
|
#
|
|
1554
|
+
# Looking up a sheet that does not exist is deprecated and warns; in version 0.3.0 it
|
|
1555
|
+
# will raise ArgumentError.
|
|
1556
|
+
#
|
|
1529
1557
|
# @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
|
|
1530
1558
|
# @yield [proxy]
|
|
1531
1559
|
# @yieldparam proxy [WorksheetProxy]
|
|
@@ -1541,6 +1569,7 @@ module Xlsxrb
|
|
|
1541
1569
|
else
|
|
1542
1570
|
name_or_index.to_s
|
|
1543
1571
|
end
|
|
1572
|
+
Deprecation.warn(UNKNOWN_SHEET_MESSAGE) unless sheet_names.include?(target_name)
|
|
1544
1573
|
proxy = WorksheetProxy.new(self, target_name)
|
|
1545
1574
|
yield proxy if block_given?
|
|
1546
1575
|
proxy
|
|
@@ -1561,9 +1590,12 @@ module Xlsxrb
|
|
|
1561
1590
|
@current_sheet_io = StringIO.new(@current_row_buffer)
|
|
1562
1591
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
1563
1592
|
@current_row_writer = Ooxml::WorksheetWriter.new(@current_sheet_io, date1904: date1904)
|
|
1593
|
+
@current_row_writer.time_like_style_resolver = method(:time_like_style_id)
|
|
1594
|
+
@current_row_writer.strict_excel_mode = @strict_excel_mode
|
|
1564
1595
|
@current_row_writer.instance_variable_set(:@started, true)
|
|
1565
1596
|
|
|
1566
1597
|
@current_columns = []
|
|
1598
|
+
@current_column_style_names = {} # column index => style name, for date style variants
|
|
1567
1599
|
@current_charts = []
|
|
1568
1600
|
@current_hyperlinks = []
|
|
1569
1601
|
@current_auto_filter = nil
|
|
@@ -1641,6 +1673,8 @@ module Xlsxrb
|
|
|
1641
1673
|
|
|
1642
1674
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
1643
1675
|
@current_row_writer = Ooxml::WorksheetWriter.new(zip_io, date1904: date1904)
|
|
1676
|
+
@current_row_writer.time_like_style_resolver = method(:time_like_style_id)
|
|
1677
|
+
@current_row_writer.strict_excel_mode = @strict_excel_mode
|
|
1644
1678
|
@current_row_writer.start(
|
|
1645
1679
|
columns: @current_columns,
|
|
1646
1680
|
sheet_properties: @current_sheet_properties.empty? ? nil : @current_sheet_properties,
|
|
@@ -1676,11 +1710,8 @@ module Xlsxrb
|
|
|
1676
1710
|
|
|
1677
1711
|
values = DslHelpers.normalize_row_values(values)
|
|
1678
1712
|
cell_styles = DslHelpers.normalize_row_styles(cell_styles)
|
|
1679
|
-
if cell_styles
|
|
1680
|
-
|
|
1681
|
-
cell_styles = with_date_style_variants(values, cell_styles)
|
|
1682
|
-
end
|
|
1683
|
-
DslHelpers.check_style_name!(row_style, @style_name_to_id)
|
|
1713
|
+
check_style_names!(cell_styles) if cell_styles
|
|
1714
|
+
check_style_name!(row_style)
|
|
1684
1715
|
|
|
1685
1716
|
if @current_charts && !@current_charts.empty?
|
|
1686
1717
|
@current_cells ||= {}
|
|
@@ -1702,6 +1733,9 @@ module Xlsxrb
|
|
|
1702
1733
|
else
|
|
1703
1734
|
row_style
|
|
1704
1735
|
end
|
|
1736
|
+
if cell_styles || row_style || !@current_column_style_names.empty?
|
|
1737
|
+
cell_styles = with_date_style_variants(values, cell_styles, row_style.is_a?(Hash) ? inline_name : row_style)
|
|
1738
|
+
end
|
|
1705
1739
|
|
|
1706
1740
|
effective_outline = outline_level || @current_row_outline_level
|
|
1707
1741
|
effective_collapsed = collapsed || @current_row_collapsed
|
|
@@ -1750,6 +1784,7 @@ module Xlsxrb
|
|
|
1750
1784
|
|
|
1751
1785
|
sheet if @current_sheet.nil?
|
|
1752
1786
|
@current_row_index += count
|
|
1787
|
+
nil
|
|
1753
1788
|
end
|
|
1754
1789
|
|
|
1755
1790
|
# Sets column formatting and properties for one or multiple columns.
|
|
@@ -1769,6 +1804,7 @@ module Xlsxrb
|
|
|
1769
1804
|
raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
|
|
1770
1805
|
|
|
1771
1806
|
sheet if @current_sheet.nil?
|
|
1807
|
+
warn_late_sheet_setting("column")
|
|
1772
1808
|
|
|
1773
1809
|
DslHelpers.check_style_name!(style, @style_name_to_id)
|
|
1774
1810
|
style_id = if style.is_a?(Hash)
|
|
@@ -1780,7 +1816,18 @@ module Xlsxrb
|
|
|
1780
1816
|
else
|
|
1781
1817
|
style
|
|
1782
1818
|
end
|
|
1819
|
+
# The style's name, so that dates in the column can get a variant of it with a date format
|
|
1820
|
+
style_name = if style.is_a?(Hash)
|
|
1821
|
+
inline_name
|
|
1822
|
+
elsif style.is_a?(String) || style.is_a?(Symbol)
|
|
1823
|
+
style.to_s
|
|
1824
|
+
end
|
|
1783
1825
|
DslHelpers.normalize_column_indices(index).each do |idx|
|
|
1826
|
+
if style_name
|
|
1827
|
+
@current_column_style_names[idx] = style_name
|
|
1828
|
+
elsif style
|
|
1829
|
+
@current_column_style_names.delete(idx)
|
|
1830
|
+
end
|
|
1784
1831
|
existing = @current_columns.find { |c| c[:index] == idx }
|
|
1785
1832
|
if existing
|
|
1786
1833
|
existing[:width] = width unless width.nil?
|
|
@@ -1891,6 +1938,7 @@ module Xlsxrb
|
|
|
1891
1938
|
@current_row_collapsed = prev_collapsed
|
|
1892
1939
|
@current_row_hidden = prev_hidden
|
|
1893
1940
|
end
|
|
1941
|
+
nil
|
|
1894
1942
|
end
|
|
1895
1943
|
|
|
1896
1944
|
# Configures or queries worksheet-level outline and grouping view properties.
|
|
@@ -1912,6 +1960,7 @@ module Xlsxrb
|
|
|
1912
1960
|
#: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
|
|
1913
1961
|
def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, apply_styles: nil, **opts)
|
|
1914
1962
|
sheet if @current_sheet.nil?
|
|
1963
|
+
warn_late_sheet_setting("outline_properties") unless summary_below.nil? && summary_right.nil? && show_outline_symbols.nil? && apply_styles.nil? && opts.empty?
|
|
1915
1964
|
|
|
1916
1965
|
return @current_sheet_properties.slice(:summary_below, :summary_right, :show_outline_symbols, :apply_styles) if summary_below.nil? && summary_right.nil? && show_outline_symbols.nil? && apply_styles.nil? && opts.empty?
|
|
1917
1966
|
|
|
@@ -2258,6 +2307,7 @@ module Xlsxrb
|
|
|
2258
2307
|
#: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
2259
2308
|
def freeze_pane(row: nil, column: nil, top_left_cell: nil, active_pane: nil)
|
|
2260
2309
|
sheet if @current_sheet.nil?
|
|
2310
|
+
warn_late_sheet_setting("freeze_pane") unless row.nil? && column.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2261
2311
|
if row.nil? && column.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2262
2312
|
return @current_freeze_pane ? Elements::FreezePane.new(**@current_freeze_pane) : nil
|
|
2263
2313
|
end
|
|
@@ -2278,6 +2328,7 @@ module Xlsxrb
|
|
|
2278
2328
|
#: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
|
|
2279
2329
|
def freeze_pane=(opts)
|
|
2280
2330
|
sheet if @current_sheet.nil?
|
|
2331
|
+
warn_late_sheet_setting("freeze_pane=")
|
|
2281
2332
|
if opts.nil?
|
|
2282
2333
|
@current_freeze_pane = nil
|
|
2283
2334
|
else
|
|
@@ -2308,6 +2359,7 @@ module Xlsxrb
|
|
|
2308
2359
|
#: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
2309
2360
|
def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil)
|
|
2310
2361
|
sheet if @current_sheet.nil?
|
|
2362
|
+
warn_late_sheet_setting("split_pane") unless x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2311
2363
|
if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2312
2364
|
return @current_split_pane ? Elements::SplitPane.new(**@current_split_pane) : nil
|
|
2313
2365
|
end
|
|
@@ -2326,6 +2378,7 @@ module Xlsxrb
|
|
|
2326
2378
|
#: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
|
|
2327
2379
|
def split_pane=(opts)
|
|
2328
2380
|
sheet if @current_sheet.nil?
|
|
2381
|
+
warn_late_sheet_setting("split_pane=")
|
|
2329
2382
|
if opts.nil?
|
|
2330
2383
|
@current_split_pane = nil
|
|
2331
2384
|
else
|
|
@@ -2351,6 +2404,7 @@ module Xlsxrb
|
|
|
2351
2404
|
#: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
|
|
2352
2405
|
def selection(active_cell = nil, sqref: nil, pane: nil)
|
|
2353
2406
|
sheet if @current_sheet.nil?
|
|
2407
|
+
warn_late_sheet_setting("selection") unless active_cell.nil? && sqref.nil? && pane.nil?
|
|
2354
2408
|
if active_cell.nil? && sqref.nil? && pane.nil?
|
|
2355
2409
|
return nil if @current_selection.nil?
|
|
2356
2410
|
return @current_selection.map { |s| Elements::Selection.new(**s) } if @current_selection.is_a?(Array)
|
|
@@ -2378,6 +2432,7 @@ module Xlsxrb
|
|
|
2378
2432
|
#: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
|
|
2379
2433
|
def selection=(opts)
|
|
2380
2434
|
sheet if @current_sheet.nil?
|
|
2435
|
+
warn_late_sheet_setting("selection=")
|
|
2381
2436
|
@current_selection = if opts.nil?
|
|
2382
2437
|
nil
|
|
2383
2438
|
elsif opts.is_a?(Array)
|
|
@@ -2444,6 +2499,7 @@ module Xlsxrb
|
|
|
2444
2499
|
#: (**untyped opts) -> void
|
|
2445
2500
|
def page_setup(**opts)
|
|
2446
2501
|
sheet if @current_sheet.nil?
|
|
2502
|
+
warn_late_sheet_setting("page_setup with fit_to_width or fit_to_height") if opts.key?(:fit_to_width) || opts.key?(:fit_to_height)
|
|
2447
2503
|
return Elements::PageSetup.new(**@current_page_setup) if opts.empty?
|
|
2448
2504
|
|
|
2449
2505
|
@current_page_setup.merge!(opts)
|
|
@@ -2710,6 +2766,7 @@ module Xlsxrb
|
|
|
2710
2766
|
#: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
|
|
2711
2767
|
def tab_color=(spec)
|
|
2712
2768
|
sheet if @current_sheet.nil?
|
|
2769
|
+
warn_late_sheet_setting("tab_color=")
|
|
2713
2770
|
@current_sheet_properties[:tab_color] = spec
|
|
2714
2771
|
end
|
|
2715
2772
|
|
|
@@ -2725,6 +2782,7 @@ module Xlsxrb
|
|
|
2725
2782
|
#: (**untyped opts) -> void
|
|
2726
2783
|
def sheet_properties(**opts)
|
|
2727
2784
|
sheet if @current_sheet.nil?
|
|
2785
|
+
warn_late_sheet_setting("sheet_properties") unless opts.empty?
|
|
2728
2786
|
return Elements::SheetProperties.new(**@current_sheet_properties) if opts.empty?
|
|
2729
2787
|
|
|
2730
2788
|
opts.each do |k, v|
|
|
@@ -2751,6 +2809,7 @@ module Xlsxrb
|
|
|
2751
2809
|
#: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
|
|
2752
2810
|
def sheet_properties=(opts)
|
|
2753
2811
|
sheet if @current_sheet.nil?
|
|
2812
|
+
warn_late_sheet_setting("sheet_properties=")
|
|
2754
2813
|
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2755
2814
|
@current_sheet_properties = {}
|
|
2756
2815
|
sheet_properties(**h)
|
|
@@ -2769,6 +2828,7 @@ module Xlsxrb
|
|
|
2769
2828
|
#: (**untyped opts) -> void
|
|
2770
2829
|
def sheet_view(**opts)
|
|
2771
2830
|
sheet if @current_sheet.nil?
|
|
2831
|
+
warn_late_sheet_setting("sheet_view") unless opts.empty?
|
|
2772
2832
|
return Elements::SheetView.new(**@current_sheet_view) if opts.empty?
|
|
2773
2833
|
|
|
2774
2834
|
opts.each { |k, v| @current_sheet_view[k.to_sym] = v }
|
|
@@ -2783,6 +2843,7 @@ module Xlsxrb
|
|
|
2783
2843
|
#: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
|
|
2784
2844
|
def sheet_view=(opts)
|
|
2785
2845
|
sheet if @current_sheet.nil?
|
|
2846
|
+
warn_late_sheet_setting("sheet_view=")
|
|
2786
2847
|
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2787
2848
|
@current_sheet_view = h.transform_keys(&:to_sym)
|
|
2788
2849
|
nil
|
|
@@ -2800,6 +2861,7 @@ module Xlsxrb
|
|
|
2800
2861
|
#: (**untyped opts) -> void
|
|
2801
2862
|
def sheet_format(**opts)
|
|
2802
2863
|
sheet if @current_sheet.nil?
|
|
2864
|
+
warn_late_sheet_setting("sheet_format") unless opts.empty?
|
|
2803
2865
|
return Elements::SheetFormat.new(**@current_sheet_format) if opts.empty?
|
|
2804
2866
|
|
|
2805
2867
|
opts.each { |k, v| @current_sheet_format[k.to_sym] = v }
|
|
@@ -2814,6 +2876,7 @@ module Xlsxrb
|
|
|
2814
2876
|
#: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
|
|
2815
2877
|
def sheet_format=(opts)
|
|
2816
2878
|
sheet if @current_sheet.nil?
|
|
2879
|
+
warn_late_sheet_setting("sheet_format=")
|
|
2817
2880
|
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2818
2881
|
@current_sheet_format = h.transform_keys(&:to_sym)
|
|
2819
2882
|
nil
|
|
@@ -2949,6 +3012,7 @@ module Xlsxrb
|
|
|
2949
3012
|
if @current_sheet.nil?
|
|
2950
3013
|
@workbook_properties[:code_name] = val&.to_s
|
|
2951
3014
|
else
|
|
3015
|
+
warn_late_sheet_setting("code_name=")
|
|
2952
3016
|
@current_sheet_properties[:code_name] = val&.to_s
|
|
2953
3017
|
end
|
|
2954
3018
|
end
|
|
@@ -2971,6 +3035,7 @@ module Xlsxrb
|
|
|
2971
3035
|
#: (bool? enabled) -> bool?
|
|
2972
3036
|
def fit_to_page=(enabled)
|
|
2973
3037
|
sheet if @current_sheet.nil?
|
|
3038
|
+
warn_late_sheet_setting("fit_to_page=")
|
|
2974
3039
|
@current_sheet_properties[:fit_to_page] = enabled ? true : false
|
|
2975
3040
|
end
|
|
2976
3041
|
|
|
@@ -3386,21 +3451,79 @@ module Xlsxrb
|
|
|
3386
3451
|
#: (untyped cell_styles) -> void
|
|
3387
3452
|
def check_style_names!(cell_styles)
|
|
3388
3453
|
if cell_styles.is_a?(Array)
|
|
3389
|
-
cell_styles.each { |name|
|
|
3454
|
+
cell_styles.each { |name| check_style_name!(name) }
|
|
3390
3455
|
else
|
|
3391
|
-
|
|
3456
|
+
check_style_name!(cell_styles)
|
|
3392
3457
|
end
|
|
3393
3458
|
end
|
|
3394
3459
|
|
|
3395
|
-
#
|
|
3396
|
-
#
|
|
3397
|
-
|
|
3398
|
-
|
|
3460
|
+
# Raises ArgumentError if +name+ is a style name that has not been defined. Defined
|
|
3461
|
+
# names return before DslHelpers.check_style_name!, whose Symbol#to_s allocates a
|
|
3462
|
+
# String for every styled cell.
|
|
3463
|
+
#: (untyped name) -> void
|
|
3464
|
+
def check_style_name!(name)
|
|
3465
|
+
return if name.is_a?(Symbol) ? @style_name_to_id.key?(name.name) : name.is_a?(String) && @style_name_to_id.key?(name)
|
|
3466
|
+
|
|
3467
|
+
DslHelpers.check_style_name!(name, @style_name_to_id)
|
|
3468
|
+
end
|
|
3469
|
+
|
|
3470
|
+
LATE_SHEET_SETTING_MESSAGE = "Calling %s after rows of the sheet are written is deprecated; call it before the first row. " \
|
|
3471
|
+
"StreamWriter writes this setting at the start of the sheet, so it is ignored once that start " \
|
|
3472
|
+
"is written, after about 64 KB of rows. In version 0.3.0, it will raise Xlsxrb::Error."
|
|
3473
|
+
private_constant :LATE_SHEET_SETTING_MESSAGE
|
|
3474
|
+
|
|
3475
|
+
# Warns when a setting that StreamWriter writes at the start of the sheet comes after
|
|
3476
|
+
# rows (or skipped rows) of the sheet. ADR 0010 makes it an error in 0.3.0.
|
|
3477
|
+
#: (String name) -> void
|
|
3478
|
+
def warn_late_sheet_setting(name)
|
|
3479
|
+
return unless @current_row_index.positive?
|
|
3480
|
+
|
|
3481
|
+
Deprecation.warn(format(LATE_SHEET_SETTING_MESSAGE, name), uplevel: nil)
|
|
3482
|
+
end
|
|
3483
|
+
|
|
3484
|
+
# The style id for a Time-like value (see Ooxml::WorksheetWriter::TimeLike) in a cell
|
|
3485
|
+
# whose style id is style_id: the date-time variant of that style when the style has no
|
|
3486
|
+
# number format, as a Time in the same cell gets from with_date_style_variants, and
|
|
3487
|
+
# style_id otherwise. Called by the worksheet writer only for such values.
|
|
3488
|
+
#: (Integer style_id) -> Integer
|
|
3489
|
+
def time_like_style_id(style_id)
|
|
3490
|
+
@time_like_style_ids[style_id] ||= begin
|
|
3491
|
+
style_name = @style_name_to_id.key(style_id)
|
|
3492
|
+
style_builder = style_name && @styles[style_name]
|
|
3493
|
+
if style_builder.nil? || style_builder.number_format
|
|
3494
|
+
style_id
|
|
3495
|
+
else
|
|
3496
|
+
variant_name = "#{style_name}__xlsxrb_time"
|
|
3497
|
+
unless @style_name_to_id.key?(variant_name)
|
|
3498
|
+
variant_builder = style_builder.with_number_format(variant_name, DslHelpers::TIME_NUMBER_FORMAT)
|
|
3499
|
+
@styles[variant_name] = variant_builder
|
|
3500
|
+
@style_name_to_id[variant_name] = variant_builder.register_with(@style_writer)
|
|
3501
|
+
end
|
|
3502
|
+
@style_name_to_id.fetch(variant_name)
|
|
3503
|
+
end
|
|
3504
|
+
end
|
|
3505
|
+
end
|
|
3506
|
+
|
|
3507
|
+
# Gives Date and Time values whose named style has no number format a variant of that
|
|
3508
|
+
# style with the default date or time format, registered on first use. A value without
|
|
3509
|
+
# a cell style gets a variant of the style it inherits: the row style, or the column
|
|
3510
|
+
# style in a row without one.
|
|
3511
|
+
#: (Array[untyped] values, untyped cell_styles, untyped row_style) -> untyped
|
|
3512
|
+
def with_date_style_variants(values, cell_styles, row_style)
|
|
3513
|
+
# This runs for every styled row. any? with a class checks the values in C, which
|
|
3514
|
+
# costs less than the loop below for the rows without dates.
|
|
3515
|
+
return cell_styles unless values.any?(Date) || values.any?(Time)
|
|
3516
|
+
|
|
3399
3517
|
styles_for_cells = cell_styles.is_a?(Array) ? cell_styles : nil
|
|
3400
|
-
|
|
3518
|
+
idx = -1
|
|
3519
|
+
last = values.size - 1
|
|
3520
|
+
while idx < last
|
|
3521
|
+
idx += 1
|
|
3522
|
+
value = values[idx]
|
|
3401
3523
|
next unless value.is_a?(Date) || value.is_a?(Time)
|
|
3402
3524
|
|
|
3403
3525
|
style_name = styles_for_cells ? styles_for_cells[idx] : cell_styles
|
|
3526
|
+
style_name = row_style.nil? ? @current_column_style_names[idx] : row_style if style_name.nil?
|
|
3404
3527
|
next unless style_name.is_a?(String) || style_name.is_a?(Symbol)
|
|
3405
3528
|
|
|
3406
3529
|
variant = DslHelpers.date_style_variant(value, style_name.to_s, @styles[style_name.to_s])
|