xlsxrb 0.1.18 → 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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +200 -0
  3. data/README.md +35 -12
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +410 -80
  5. data/lib/xlsxrb/chart_builder.rb +251 -386
  6. data/lib/xlsxrb/dsl_helpers.rb +169 -68
  7. data/lib/xlsxrb/elements/cell.rb +37 -157
  8. data/lib/xlsxrb/elements/column.rb +11 -19
  9. data/lib/xlsxrb/elements/coordinate_access.rb +15 -86
  10. data/lib/xlsxrb/elements/image.rb +5 -72
  11. data/lib/xlsxrb/elements/metadata.rb +463 -817
  12. data/lib/xlsxrb/elements/row.rb +27 -145
  13. data/lib/xlsxrb/elements/styles.rb +30 -88
  14. data/lib/xlsxrb/elements/types.rb +6 -99
  15. data/lib/xlsxrb/elements/workbook.rb +19 -126
  16. data/lib/xlsxrb/elements/worksheet.rb +45 -316
  17. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +4 -1
  18. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -7
  19. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +32 -17
  20. data/lib/xlsxrb/ooxml/reader.rb +49 -51
  21. data/lib/xlsxrb/ooxml/styles_parser.rb +26 -2
  22. data/lib/xlsxrb/ooxml/utils.rb +15 -2
  23. data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +184 -94
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +61 -29
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +353 -261
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +28 -11
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +62 -16
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +1 -1
  30. data/lib/xlsxrb/ooxml/writer.rb +106 -42
  31. data/lib/xlsxrb/ooxml/xml_builder.rb +18 -0
  32. data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +65 -15
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
  35. data/lib/xlsxrb/stream_row.rb +14 -118
  36. data/lib/xlsxrb/stream_sheet.rb +14 -261
  37. data/lib/xlsxrb/stream_writer.rb +807 -1537
  38. data/lib/xlsxrb/style_builder.rb +715 -593
  39. data/lib/xlsxrb/version.rb +1 -1
  40. data/lib/xlsxrb/workbook_builder.rb +403 -286
  41. data/lib/xlsxrb/worksheet_builder.rb +1297 -1458
  42. data/lib/xlsxrb.rb +281 -1079
  43. data/sig/generated/xlsxrb/chart_builder.rbs +202 -205
  44. data/sig/generated/xlsxrb/dsl_helpers.rbs +92 -16
  45. data/sig/generated/xlsxrb/elements/cell.rbs +12 -76
  46. data/sig/generated/xlsxrb/elements/column.rbs +0 -7
  47. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +5 -41
  48. data/sig/generated/xlsxrb/elements/image.rbs +3 -29
  49. data/sig/generated/xlsxrb/elements/metadata.rbs +138 -151
  50. data/sig/generated/xlsxrb/elements/row.rbs +10 -53
  51. data/sig/generated/xlsxrb/elements/styles.rbs +1 -39
  52. data/sig/generated/xlsxrb/elements/workbook.rbs +14 -78
  53. data/sig/generated/xlsxrb/elements/worksheet.rbs +5 -121
  54. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +0 -4
  55. data/sig/generated/xlsxrb/ooxml/reader.rbs +0 -3
  56. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
  57. data/sig/generated/xlsxrb/ooxml/utils.rbs +13 -3
  58. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +17 -0
  59. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
  60. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +58 -3
  61. data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +10 -0
  62. data/sig/generated/xlsxrb/ooxml/writer.rbs +20 -14
  63. data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +12 -0
  64. data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
  65. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +22 -7
  66. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
  67. data/sig/generated/xlsxrb/stream_row.rbs +9 -44
  68. data/sig/generated/xlsxrb/stream_sheet.rbs +1 -158
  69. data/sig/generated/xlsxrb/stream_writer.rbs +491 -974
  70. data/sig/generated/xlsxrb/style_builder.rbs +464 -239
  71. data/sig/generated/xlsxrb/workbook_builder.rbs +124 -139
  72. data/sig/generated/xlsxrb/worksheet_builder.rbs +922 -686
  73. data/sig/generated/xlsxrb.rbs +56 -188
  74. data/sig/rexml.rbs +8 -0
  75. metadata +3 -5
  76. data/lib/xlsxrb/utils.rb +0 -251
  77. data/sig/generated/xlsxrb/utils.rbs +0 -200
@@ -32,19 +32,6 @@ module Xlsxrb
32
32
  #: String?
33
33
  attr_reader :current_sheet
34
34
 
35
- # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
36
- #: bool
37
- attr_accessor :escape_formulas
38
-
39
- # Returns whether formula escaping is enabled.
40
- #
41
- # @return [Boolean]
42
- # @api public
43
- #: () -> bool
44
- def escape_formulas?
45
- @escape_formulas ? true : false
46
- end
47
-
48
35
  # Returns whether the shared strings table is enabled.
49
36
  #
50
37
  # @return [Boolean]
@@ -54,13 +41,6 @@ module Xlsxrb
54
41
  @shared_strings ? true : false
55
42
  end
56
43
 
57
- # @deprecated Use {#shared_strings?} instead. Will be removed in 0.2.0.
58
- #: () -> bool
59
- def shared_strings
60
- warn "[DEPRECATION] StreamWriter#shared_strings is deprecated; use #shared_strings? instead.", uplevel: 1
61
- shared_strings?
62
- end
63
-
64
44
  # @return [Integer] The ZIP deflate compression level (0..9).
65
45
  #: Integer
66
46
  attr_reader :compression_level
@@ -73,22 +53,20 @@ module Xlsxrb
73
53
  #
74
54
  # @param target [String, IO, StringIO] Destination file path or writable IO stream.
75
55
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
76
- # @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
77
56
  # @param default_font [Hash, nil] Optional default font options (e.g. `{ name: "Arial", size: 12 }`).
78
57
  # @param shared_strings [Boolean] Whether to intern strings into a shared strings table (`xl/sharedStrings.xml`).
79
58
  # When set to `false`, strings are written directly as inline strings (`<c t="inlineStr">`), maintaining flat
80
59
  # $O(1)$ constant memory regardless of row count or unique string cardinality. Note that disabling shared strings
81
60
  # may slightly increase archive size (typically 3-5%) on datasets with high repetition.
82
- # @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION).
83
- # Level 6 is standard. Level 4 accelerates compression by 20-40% with an ~10% size tradeoff,
84
- # recommended for high-throughput streaming exports. Level 0 disables compression (store only).
85
- #: (untyped target, ?strict_excel_mode: bool, ?escape_formulas: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) -> void
86
- def initialize(target, strict_excel_mode: true, escape_formulas: false, default_font: nil, shared_strings: true, compression_level: Zlib::DEFAULT_COMPRESSION)
61
+ # @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION
62
+ # for zlib's level 6). Defaults to {Xlsxrb::DEFAULT_COMPRESSION_LEVEL}. Higher levels write smaller files more slowly;
63
+ # level 0 stores entries without compression. See docs/adr/0009-default-zip-compression-level.md.
64
+ #: (untyped target, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) -> void
65
+ def initialize(target, strict_excel_mode: true, default_font: nil, shared_strings: true, compression_level: DEFAULT_COMPRESSION_LEVEL)
87
66
  @target = target
88
67
  @strict_excel_mode = strict_excel_mode
89
- @escape_formulas = escape_formulas ? true : false
90
68
  @shared_strings = shared_strings ? true : false
91
- @compression_level = compression_level || Zlib::DEFAULT_COMPRESSION
69
+ @compression_level = compression_level || DEFAULT_COMPRESSION_LEVEL
92
70
  @io = target.is_a?(String) ? File.open(target, "wb") : target
93
71
  @owns_io = target.is_a?(String)
94
72
  @zip = Ooxml::ZipWriter.new(@io, compression_level: @compression_level)
@@ -106,6 +84,7 @@ module Xlsxrb
106
84
  @sheet_entry_started = false
107
85
  @current_row_writer = nil
108
86
  @current_columns = []
87
+ @current_column_style_names = {} # column index => style name, for date style variants
109
88
  @current_charts = []
110
89
  @current_hyperlinks = []
111
90
  @current_auto_filter = nil
@@ -149,8 +128,9 @@ module Xlsxrb
149
128
  @styles = {} # { style_name => StyleBuilder }
150
129
  @style_writer = Ooxml::Writer.new(default_font: default_font)
151
130
  @style_name_to_id = {}
152
- style("__xlsxrb_date", number_format: "yyyy-mm-dd")
153
- style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss")
131
+ @time_like_style_ids = {} # cell style id => style id for Time-like values, see time_like_style_id
132
+ style("__xlsxrb_date", number_format: DslHelpers::DATE_NUMBER_FORMAT)
133
+ style("__xlsxrb_time", number_format: DslHelpers::TIME_NUMBER_FORMAT)
154
134
  # Workbook-level settings
155
135
  @defined_names = []
156
136
  @core_properties = {}
@@ -169,119 +149,50 @@ module Xlsxrb
169
149
  # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
170
150
  # @return [String, Symbol, Integer, nil]
171
151
  # @api public
172
- # Gets or sets the active worksheet tab in the workbook window.
173
- #
174
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#active_sheet=} instead.
175
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
176
- # @return [String, Symbol, Integer, nil]
177
- # @api public
178
- #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
179
- def active_sheet(name_or_index = OMITTED)
180
- if name_or_index.equal?(OMITTED)
181
- @active_sheet
182
- else
183
- @active_sheet = name_or_index
184
- end
185
- end
186
- # @deprecated Use {#active_sheet} instead. Will be removed in 0.2.0.
187
- alias active_tab active_sheet
188
-
189
- # Sets the active worksheet tab in the workbook window.
190
- #
191
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
192
- # @return [String, Symbol, Integer, nil]
193
- # @api public
194
- attr_writer :active_sheet #: (String | Symbol | Integer | nil)
195
- # @deprecated Use {#active_sheet=} instead. Will be removed in 0.2.0.
196
- alias active_tab= active_sheet=
197
-
198
- # Gets or sets the first sheet tab visible in the sheet tab scroll area.
199
- #
200
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#first_sheet=} instead.
201
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
152
+ # Active worksheet tab in the workbook window.
202
153
  # @return [String, Symbol, Integer, nil]
203
154
  # @api public
204
- #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
205
- def first_sheet(name_or_index = OMITTED)
206
- if name_or_index.equal?(OMITTED)
207
- @first_sheet
208
- else
209
- @first_sheet = name_or_index
210
- end
211
- end
155
+ attr_accessor :active_sheet #: (String | Symbol | Integer | nil)
212
156
 
213
- # Sets the first sheet tab visible in the sheet tab scroll area.
214
- #
215
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
157
+ # First sheet tab visible in the sheet tab scroll area.
216
158
  # @return [String, Symbol, Integer, nil]
217
159
  # @api public
218
- attr_writer :first_sheet #: (String | Symbol | Integer | nil)
219
-
220
- # Gets or sets whether sheet tabs are visible in the workbook window.
221
- #
222
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_sheet_tabs=} instead.
223
- # @param visible [Boolean, nil]
224
- # @return [Boolean, nil]
225
- # @api public
226
- #: (?bool? visible) -> bool?
227
- def show_sheet_tabs(visible = OMITTED)
228
- if visible.equal?(OMITTED)
229
- @show_sheet_tabs
230
- else
231
- @show_sheet_tabs = visible
232
- end
233
- end
160
+ attr_accessor :first_sheet #: (String | Symbol | Integer | nil)
234
161
 
235
162
  # Sets whether sheet tabs are visible in the workbook window.
236
- #
237
163
  # @param visible [Boolean, nil]
238
164
  # @return [Boolean, nil]
239
165
  # @api public
240
- attr_writer :show_sheet_tabs #: bool?
166
+ attr_writer :show_sheet_tabs #: (bool?) -> bool?
241
167
 
242
- # Gets or sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
243
- #
244
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_ratio=} instead.
245
- # @param ratio [Integer, nil]
246
- # @return [Integer, nil]
168
+ # Returns whether sheet tabs are visible in the workbook window.
169
+ # @return [Boolean]
247
170
  # @api public
248
- #: (?Integer? ratio) -> Integer?
249
- def tab_ratio(ratio = OMITTED)
250
- if ratio.equal?(OMITTED)
251
- @tab_ratio
252
- else
253
- @tab_ratio = ratio
254
- end
171
+ #: () -> bool
172
+ def show_sheet_tabs?
173
+ @show_sheet_tabs != false
255
174
  end
256
175
 
257
- # Sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
258
- #
259
- # @param ratio [Integer, nil]
176
+ # Ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
260
177
  # @return [Integer, nil]
261
178
  # @api public
262
- attr_writer :tab_ratio #: Integer?
179
+ attr_accessor :tab_ratio #: Integer?
263
180
 
264
- # Sets a workbook property.
181
+ # Configures or queries workbook-level properties.
265
182
  #
266
- # @note **SECURITY WARNING:** If you set `:update_links` to anything other than `"never"`,
267
- # you may expose end-users to malicious external reference vulnerabilities (e.g., CSV/DDE Injection)
268
- # when they open the generated Excel file. Ensure you fully trust the exported data.
183
+ # When called with no arguments, returns the {Elements::WorkbookProperties} value object.
184
+ # When called with keyword options, configures properties and returns nil.
269
185
  #
270
- # @param name [Symbol] Property name (e.g. :update_links).
271
- # @param value [String, Integer, Boolean] Property value.
272
- # @return [void]
273
- #: (Symbol name, String | Integer | bool value) -> void
274
- def workbook_property(name, value)
275
- @workbook_properties[name] = value
276
- end
277
-
278
- # Returns workbook-level properties.
279
- #
280
- # @return [Elements::WorkbookProperties]
186
+ # @param opts [Hash] Workbook properties map.
187
+ # @return [Elements::WorkbookProperties, void]
281
188
  # @api public
282
189
  #: () -> Elements::WorkbookProperties
283
- def workbook_properties
284
- Elements::WorkbookProperties.new(**@workbook_properties)
190
+ #: (**untyped opts) -> void
191
+ def workbook_properties(**opts)
192
+ return Elements::WorkbookProperties.new(**@workbook_properties) if opts.empty?
193
+
194
+ @workbook_properties.merge!(opts)
195
+ nil
285
196
  end
286
197
 
287
198
  # Sets workbook-level properties.
@@ -291,7 +202,9 @@ module Xlsxrb
291
202
  # @api public
292
203
  #: (untyped props) -> void
293
204
  def workbook_properties=(props)
294
- @workbook_properties = props.is_a?(Elements::MetadataRecord) ? props.to_h : props
205
+ h = props.respond_to?(:to_h) ? props.to_h : (props || {})
206
+ @workbook_properties = h.transform_keys(&:to_sym)
207
+ nil
295
208
  end
296
209
 
297
210
  # Defines or configures a named cell style.
@@ -301,6 +214,8 @@ module Xlsxrb
301
214
  # @yield [style_builder]
302
215
  # @yieldparam style_builder [Xlsxrb::StyleBuilder]
303
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.
304
219
  #: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
305
220
  def style(name, **opts)
306
221
  style_name = name.to_s
@@ -311,8 +226,14 @@ module Xlsxrb
311
226
 
312
227
  # Register immediately with low-level style writer
313
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
314
235
 
315
- style_builder
236
+ ReturnedStyleBuilder.new(style_builder)
316
237
  end
317
238
 
318
239
  # Sets or configures the workbook-wide default font.
@@ -326,8 +247,6 @@ module Xlsxrb
326
247
  def default_font(name = nil, size = nil, **opts)
327
248
  @style_writer.default_font(name, size, **opts)
328
249
  end
329
- # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
330
- alias set_default_font default_font
331
250
 
332
251
  # Creates an {Elements::Formula} object.
333
252
  # @api public
@@ -375,19 +294,14 @@ module Xlsxrb
375
294
  @sheet_name = sheet_name
376
295
  end
377
296
 
378
- # Sets or configures the workbook-wide default font.
297
+ # Returns the worksheet name.
379
298
  #
380
- # @param name [String, Hash, nil] Font name or font options Hash.
381
- # @param size [Float, Integer, nil] Font size in points.
382
- # @param opts [Hash] Additional font options.
383
- # @return [void]
299
+ # @return [String]
384
300
  # @api public
385
- #: (?String | Hash[Symbol, untyped]? name, ?Float | Integer | nil size, **untyped opts) -> void
386
- def default_font(...)
387
- @writer.default_font(...)
301
+ #: () -> String
302
+ def name
303
+ @sheet_name
388
304
  end
389
- # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
390
- alias set_default_font default_font
391
305
 
392
306
  # Creates an {Elements::Formula} object.
393
307
  # @api public
@@ -424,58 +338,6 @@ module Xlsxrb
424
338
  Xlsxrb.cell_error(...)
425
339
  end
426
340
 
427
- # Returns the worksheet name.
428
- #
429
- # @return [String]
430
- # @api public
431
- #: () -> String
432
- def name
433
- @sheet_name
434
- end
435
-
436
- # Returns column configurations defined for this worksheet.
437
- #
438
- # @return [Array<Elements::Column>]
439
- # @api public
440
- #: () -> Array[Elements::Column]
441
- def columns
442
- @writer.columns
443
- end
444
-
445
- # Returns the list of worksheet names created in this workbook so far.
446
- #
447
- # @return [Array<String>] Worksheet names.
448
- # @api public
449
- #: () -> Array[String]
450
- def sheet_names
451
- @writer.sheet_names
452
- end
453
-
454
- # Returns whether formula escaping is enabled.
455
- #
456
- # @return [Boolean]
457
- # @api public
458
- #: () -> bool
459
- def escape_formulas?
460
- @writer.escape_formulas?
461
- end
462
-
463
- # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
464
- #: bool
465
- def escape_formulas
466
- @writer.escape_formulas
467
- end
468
-
469
- # Sets whether to treat strings starting with formula prefixes as plain text.
470
- #
471
- # @param val [Boolean]
472
- # @return [Boolean]
473
- # @api public
474
- #: (bool val) -> bool
475
- def escape_formulas=(val, ...)
476
- @writer.escape_formulas = val
477
- end
478
-
479
341
  # Defines or configures a named cell style on the active sheet.
480
342
  #
481
343
  # @example
@@ -489,7 +351,7 @@ module Xlsxrb
489
351
  # @api public
490
352
  #: (String | Symbol name, **untyped opts) ?{ (Xlsxrb::StyleBuilder) -> void } -> Xlsxrb::StyleBuilder
491
353
  def style(...)
492
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
354
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
493
355
 
494
356
  @writer.style(...)
495
357
  end
@@ -499,18 +361,12 @@ module Xlsxrb
499
361
  # @example Merge with cell reference string
500
362
  # s.merge("A1:C1")
501
363
  #
502
- # @deprecated Passing coordinate keyword arguments (row:, col_start:, col_end:, row_start:, row_end:) is deprecated and will be removed in 0.2.0. Use a range string (e.g. merge("A1:C1")) instead.
503
- # @param range [String, Hash, nil] The cell range (e.g. "A1:B2").
504
- # @param row [Integer, nil] 0-based row index.
505
- # @param col_start [Integer, String, nil] 0-based start column index or letter.
506
- # @param col_end [Integer, String, nil] 0-based end column index or letter.
507
- # @param row_start [Integer, nil] 0-based start row index.
508
- # @param row_end [Integer, nil] 0-based end row index.
364
+ # @param range [String] The cell range (e.g. "A1:B2").
509
365
  # @return [void]
510
366
  # @api public
511
- #: (?(String | Hash[Symbol, Integer | String])? range, ?row: Integer | nil, ?col_start: (Integer | String)?, ?col_end: (Integer | String)?, ?row_start: Integer | nil, ?row_end: Integer | nil) -> void
367
+ #: (String range) -> void
512
368
  def merge(...)
513
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
369
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
514
370
 
515
371
  @writer.merge(...)
516
372
  end
@@ -518,37 +374,24 @@ module Xlsxrb
518
374
  # Adds a drawing shape to the sheet.
519
375
  #
520
376
  # @example
521
- # s.shape(preset: "ellipse", text: "Circle", from_col: 1, from_row: 1, to_col: 4, to_row: 5)
377
+ # s.shape(preset: "ellipse", text: "Circle", from_column: 1, from_row: 1, to_column: 4, to_row: 5)
522
378
  #
523
379
  # @param preset [String] Preset shape type (e.g. "rect", "ellipse").
524
380
  # @param text [String, nil] Shape label text.
525
381
  # @param from_column [Integer, nil] Starting column index (0-based).
526
- # @param from_col [Integer, nil] Deprecated alias for from_column.
527
382
  # @param from_row [Integer] Starting row index (0-based).
528
383
  # @param to_column [Integer, nil] Ending column index (0-based).
529
- # @param to_col [Integer, nil] Deprecated alias for to_column.
530
384
  # @param to_row [Integer] Ending row index (0-based).
531
385
  # @param opts [Hash] Additional shape formatting options.
532
386
  # @return [void]
533
387
  # @api public
534
- #: (?preset: String, ?text: String?, ?from_column: Integer?, ?from_col: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_col: Integer?, ?to_row: Integer, **untyped opts) -> void
388
+ #: (?preset: String, ?text: String?, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
535
389
  def shape(...)
536
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
390
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
537
391
 
538
392
  @writer.shape(...)
539
393
  end
540
394
 
541
- # simplecov:disable
542
- # Edge case / untested delegation block
543
- # @api private
544
- #: (*untyped args, **untyped kwargs) ?{ (*untyped) -> untyped } -> untyped
545
- def internal_sheet_setup(...)
546
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
547
-
548
- @writer.internal_sheet_setup(...)
549
- end
550
- # simplecov:enable
551
-
552
395
  # Appends a row of cells to the active sheet.
553
396
  #
554
397
  # @example Write an array of values
@@ -565,27 +408,14 @@ module Xlsxrb
565
408
  # @param custom_height [Boolean] Whether to flag as custom height.
566
409
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
567
410
  # @param collapsed [Boolean] Whether the row is collapsed.
568
- # @param styles [String, Symbol, Array, Hash, nil] Deprecated. Use cell_styles: instead.
569
- # @param style [Integer, Symbol, String, Hash, nil] Deprecated. Use row_style: instead.
570
411
  # @return [void]
571
412
  # @api public
572
- #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?styles: untyped, ?style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
573
- def row(values, cell_styles: nil, row_style: nil, styles: nil, style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
574
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
575
-
576
- if styles
577
- warn "[DEPRECATION] WorksheetProxy#row keyword :styles is deprecated; use :cell_styles instead.", uplevel: 1
578
- cell_styles ||= styles
579
- end
580
- if style
581
- warn "[DEPRECATION] WorksheetProxy#row keyword :style is deprecated; use :row_style instead.", uplevel: 1
582
- row_style ||= style
583
- end
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
414
+ def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
415
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
584
416
 
585
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)
586
418
  end
587
- # @deprecated Use {#row} instead. Will be removed in 0.2.0.
588
- alias add_row row
589
419
 
590
420
  # Appends a row to the worksheet and returns self for chaining.
591
421
  #
@@ -603,9 +433,6 @@ module Xlsxrb
603
433
 
604
434
  # Advances the row cursor by count without writing empty row elements.
605
435
  #
606
- # @example Skip one row
607
- # s.skip_row
608
- #
609
436
  # @example Skip multiple rows
610
437
  # s.skip_rows(3)
611
438
  #
@@ -614,12 +441,10 @@ module Xlsxrb
614
441
  # @api public
615
442
  #: (?Integer count) -> void
616
443
  def skip_rows(count = 1)
617
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
444
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
618
445
 
619
446
  @writer.skip_rows(count)
620
447
  end
621
- # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
622
- alias skip_row skip_rows
623
448
 
624
449
  # Configures column width and properties.
625
450
  #
@@ -638,7 +463,7 @@ module Xlsxrb
638
463
  # @api public
639
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
640
465
  def column(...)
641
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
466
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
642
467
 
643
468
  @writer.column(...)
644
469
  end
@@ -655,16 +480,10 @@ module Xlsxrb
655
480
  # @api public
656
481
  #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?level: Integer, ?collapsed: bool, ?hidden: bool, ?width: Float | Integer | nil, ?style: untyped) -> void
657
482
  def group_columns(...)
658
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
483
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
659
484
 
660
485
  @writer.group_columns(...)
661
486
  end
662
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
663
- alias group_column group_columns
664
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
665
- alias group_cols group_columns
666
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
667
- alias group_col group_columns
668
487
 
669
488
  # Groups multiple rows with outline hierarchy with a block.
670
489
  #
@@ -677,7 +496,7 @@ module Xlsxrb
677
496
  # @api public
678
497
  #: (?untyped rows, ?level: Integer, ?collapsed: bool, ?hidden: bool) ?{ (self) -> void } -> void
679
498
  def group_rows(rows = nil, level: 1, collapsed: false, hidden: false)
680
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
499
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
681
500
 
682
501
  if block_given?
683
502
  @writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden) do
@@ -687,47 +506,41 @@ module Xlsxrb
687
506
  @writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden)
688
507
  end
689
508
  end
690
- # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
691
- alias group_row group_rows
692
509
 
693
- # Configures worksheet-level outline and grouping view properties.
510
+ # Configures or queries worksheet-level outline and grouping view properties.
694
511
  #
695
512
  # @param summary_below [Boolean, nil] Summary rows below detail rows.
696
513
  # @param summary_right [Boolean, nil] Summary columns to the right of detail columns.
697
514
  # @param show_outline_symbols [Boolean, nil] Outline symbols visible.
698
- # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
699
515
  # @param apply_styles [Boolean, nil] Automatic styles applied.
700
516
  # @param opts [Hash] Additional options.
701
- # @return [void]
517
+ # @return [Hash<Symbol, untyped>, void]
702
518
  # @api public
703
- #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
704
- def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, show_symbols: nil, apply_styles: nil, **opts)
705
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
519
+ #: () -> Hash[Symbol, untyped]
520
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
521
+ def outline_properties(...)
522
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
706
523
 
707
- warn "[Xlsxrb DEPRECATION] outline_properties keyword show_symbols: is deprecated; use show_outline_symbols: instead.", uplevel: 1 unless show_symbols.nil?
708
- @writer.outline_properties(summary_below: summary_below, summary_right: summary_right, show_outline_symbols: show_outline_symbols || show_symbols, apply_styles: apply_styles, **opts)
524
+ @writer.outline_properties(...)
709
525
  end
710
- # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
711
- alias outline_pr outline_properties
712
526
 
713
- # Sets worksheet outline and grouping view properties.
527
+ # Sets worksheet-level outline and grouping view properties.
714
528
  #
715
529
  # @param opts [Hash] Outline properties.
716
530
  # @return [void]
717
531
  # @api public
718
532
  #: (Hash[Symbol, untyped] opts) -> void
719
533
  def outline_properties=(opts)
720
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
534
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
721
535
 
722
536
  @writer.outline_properties = opts
723
537
  end
724
- alias outline_pr= outline_properties=
725
538
 
726
539
  # Adds a chart to the active sheet.
727
540
  #
728
541
  # @example
729
542
  # s.chart(:bar) do |chart_builder|
730
- # chart_builder.title("Quarterly Sales")
543
+ # chart_builder.title = "Quarterly Sales"
731
544
  # chart_builder.series(values: "Sheet1!$B$2:$B$5", categories: "Sheet1!$A$2:$A$5", name: "Revenue")
732
545
  # end
733
546
  #
@@ -739,7 +552,7 @@ module Xlsxrb
739
552
  # @api public
740
553
  #: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
741
554
  def chart(...)
742
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
555
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
743
556
 
744
557
  @writer.chart(...)
745
558
  end
@@ -761,24 +574,20 @@ module Xlsxrb
761
574
  # @api public
762
575
  #: (String | Integer cell, ?(String | Elements::Hyperlink)? url, ?display: String?, ?tooltip: String?, ?location: String?) -> void
763
576
  def hyperlink(...)
764
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
577
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
765
578
 
766
579
  @writer.hyperlink(...)
767
580
  end
768
581
 
769
- # Sets the auto-filter range on the active sheet.
582
+ # Returns the auto-filter range on the active sheet, or nil if none.
770
583
  #
771
- # @example
772
- # s.auto_filter("A1:D100")
773
- #
774
- # @param range [String, nil] The cell range (e.g. "A1:D10").
775
- # @return [void]
584
+ # @return [String, nil]
776
585
  # @api public
777
- #: (String? range) -> void
778
- def auto_filter(...)
779
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
586
+ #: () -> String?
587
+ def auto_filter
588
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
780
589
 
781
- @writer.auto_filter(...)
590
+ @writer.auto_filter
782
591
  end
783
592
 
784
593
  # Sets the auto-filter range on the active sheet.
@@ -788,7 +597,7 @@ module Xlsxrb
788
597
  # @api public
789
598
  #: (String? range) -> String?
790
599
  def auto_filter=(range)
791
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
600
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
792
601
 
793
602
  @writer.auto_filter = range
794
603
  end
@@ -802,38 +611,39 @@ module Xlsxrb
802
611
  # @param filter [Hash] Values or filter specification hash.
803
612
  # @return [void]
804
613
  # @api public
805
- #: (Integer | String | Symbol col_id, Hash[untyped, untyped] filter) -> void
614
+ #: (Integer | String | Symbol col_id, (Hash[untyped, untyped] | Array[untyped]) filter) -> void
806
615
  def filter_column(...)
807
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
616
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
808
617
 
809
618
  @writer.filter_column(...)
810
619
  end
811
620
 
812
- # Configures sort state on a range.
621
+ # Configures or queries sort state on a range.
813
622
  #
814
- # @example
815
- # s.sort_state("A1:A10", [{ ref: "A1:A10", descending: true }])
623
+ # When called with no arguments, returns the {Elements::SortState} value object.
624
+ # When called with arguments, updates sort state and returns nil.
816
625
  #
817
- # @param ref [String] The range to sort.
818
- # @param sort_conditions [Array<Hash>] Sort conditions array.
626
+ # @param ref [String, nil] The range to sort.
627
+ # @param sort_conditions [Array<Hash>, nil] Sort conditions array.
819
628
  # @param opts [Hash] Additional sort options.
820
- # @return [void]
629
+ # @return [Elements::SortState, nil, void]
821
630
  # @api public
822
- #: (String ref, Array[Hash[untyped, untyped]] sort_conditions, **untyped opts) -> void
631
+ #: () -> Elements::SortState?
632
+ #: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> void
823
633
  def sort_state(...)
824
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
634
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
825
635
 
826
636
  @writer.sort_state(...)
827
637
  end
828
638
 
829
- # Sets column sort state for the sheet.
639
+ # Sets sort state configuration for the active sheet.
830
640
  #
831
641
  # @param opts [Elements::SortState, Hash, nil] Sort state options.
832
642
  # @return [void]
833
643
  # @api public
834
- #: (untyped opts) -> void
644
+ #: (Elements::SortState | Hash[Symbol, untyped] | nil opts) -> void
835
645
  def sort_state=(opts)
836
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
646
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
837
647
 
838
648
  @writer.sort_state = opts
839
649
  end
@@ -845,8 +655,8 @@ module Xlsxrb
845
655
  #
846
656
  # @example Block syntax
847
657
  # s.data_validation("B2:B100") do |dv|
848
- # dv.type :list
849
- # dv.formula1 '"High,Medium,Low"'
658
+ # dv.type = :list
659
+ # dv.formula1 = '"High,Medium,Low"'
850
660
  # end
851
661
  #
852
662
  # @param range [String, nil] The cell range (e.g. "B2:B10").
@@ -857,18 +667,11 @@ module Xlsxrb
857
667
  # @api public
858
668
  #: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
859
669
  def data_validation(...)
860
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
670
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
861
671
 
862
672
  @writer.data_validation(...)
863
673
  end
864
674
 
865
- # @deprecated Use {#data_validation} instead.
866
- #: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
867
- def validate_data(...)
868
- warn "[DEPRECATION] `validate_data` is deprecated; use `data_validation` instead.", uplevel: 1
869
- data_validation(...)
870
- end
871
-
872
675
  # Adds conditional formatting to a range.
873
676
  #
874
677
  # @example Highlight values greater than 100
@@ -888,7 +691,7 @@ module Xlsxrb
888
691
  # @api public
889
692
  #: (?String? sqref, ?type: String | Symbol, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> void
890
693
  def conditional_format(sqref = nil, **opts, &)
891
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
694
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
892
695
 
893
696
  @writer.conditional_format(sqref, **opts, &)
894
697
  end
@@ -900,8 +703,8 @@ module Xlsxrb
900
703
  #
901
704
  # @example Block syntax
902
705
  # s.table("A1:C10") do |t|
903
- # t.columns ["ID", "Name", "Total"]
904
- # t.style "TableStyleMedium9"
706
+ # t.columns = ["ID", "Name", "Total"]
707
+ # t.style = "TableStyleMedium9"
905
708
  # end
906
709
  #
907
710
  # @param ref [String, nil] The cell range for the table (e.g. "A1:D10").
@@ -915,22 +718,11 @@ module Xlsxrb
915
718
  # @api public
916
719
  #: (?String? ref, ?columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) ?{ (TableBuilder) -> void } -> void
917
720
  def table(...)
918
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
721
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
919
722
 
920
723
  @writer.table(...)
921
724
  end
922
725
 
923
- # simplecov:disable
924
- # Edge case / untested delegation block
925
- # @api private
926
- #: () -> void
927
- def cleanup!(...)
928
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
929
-
930
- @writer.cleanup!(...)
931
- end
932
- # simplecov:enable
933
-
934
726
  # Adds a comment to a cell.
935
727
  #
936
728
  # @example
@@ -939,11 +731,12 @@ module Xlsxrb
939
731
  # @param cell [String, Integer] The cell reference (e.g. "A1").
940
732
  # @param text [String] The comment text.
941
733
  # @param author [String] The author name.
734
+ # @param visible [Boolean] Whether the comment is always shown instead of on hover.
942
735
  # @return [void]
943
736
  # @api public
944
- #: (String | Integer cell, String text, ?author: String) -> void
737
+ #: (String | Integer cell, String text, ?author: String, ?visible: bool) -> void
945
738
  def comment(...)
946
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
739
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
947
740
 
948
741
  @writer.comment(...)
949
742
  end
@@ -953,36 +746,32 @@ module Xlsxrb
953
746
  # @param cell [String, Integer] The cell reference (e.g. "A1").
954
747
  # @param text [String] The comment text.
955
748
  # @param author [String] The author name.
956
- # @param opts [Hash] Options: timestamp, id, parent_id, done, user_id, provider_id.
749
+ # @param visible [Boolean] Whether the comment is always shown instead of on hover. # @param opts [Hash] Options: timestamp, id, parent_id, done, user_id, provider_id.
957
750
  # @return [void]
958
751
  # @api public
959
752
  #: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
960
753
  def threaded_comment(...)
961
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
754
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
962
755
 
963
756
  @writer.threaded_comment(...)
964
757
  end
965
- # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
966
- alias add_threaded_comment threaded_comment
967
758
 
968
759
  # Adds a Pivot Table to the sheet.
969
760
  #
970
761
  # @param source_ref [String] Source data range reference (e.g. "Sheet1!A1:D100").
971
762
  # @param row_fields [Array<String>] Field names for rows.
972
763
  # @param data_fields [Array<String>] Field names for data values.
973
- # @param column_fields [Array<String>] Field names for columns.
974
- # @param col_fields [Array<String>] Deprecated alias for column_fields.
975
- # @param ref [String] Target top-left cell reference (default: "E1").
976
- # @param dest_ref [String] Deprecated alias for ref.
764
+ # @param column_fields [Array<String>, nil] Field names for columns.
765
+ # @param ref [String, nil] Target top-left cell reference (default: "E1").
977
766
  # @param name [String, nil] Pivot table name.
978
767
  # @param field_names [Array<String>, nil] Override field names.
979
- # @param items [Array, nil] Items configuration.
768
+ # @param items [Hash{Integer => Array}, nil] Items of each field, by 0-based field index.
980
769
  # @param opts [Hash] Additional options.
981
770
  # @return [void]
982
771
  # @api public
983
- #: (String source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?col_fields: untyped, ?ref: String?, ?dest_ref: String?, ?name: String?, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
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
984
773
  def pivot_table(...)
985
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
774
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
986
775
 
987
776
  @writer.pivot_table(...)
988
777
  end
@@ -999,166 +788,20 @@ module Xlsxrb
999
788
  # @api public
1000
789
  #: (sparklines: Array[Hash[Symbol, untyped]], ?type: (String | Symbol)?, **untyped opts) -> void
1001
790
  def sparkline_group(...)
1002
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
791
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1003
792
 
1004
793
  @writer.sparkline_group(...)
1005
794
  end
1006
795
 
1007
- # Adds a single sparkline to the sheet.
1008
- #
1009
- # @example Add a line sparkline
1010
- # s.add_sparkline(location: "F1", range: "A1:E1")
1011
- #
1012
- # @example Add a column sparkline with high/low markers
1013
- # s.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
1014
- #
1015
- # @example Add a win/loss sparkline
1016
- # s.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
1017
- #
1018
- # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
1019
- # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
1020
- # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
1021
- # @param opts [Hash] Additional sparkline options.
1022
- # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
1023
- # @return [void]
1024
- # @api public
1025
- #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
1026
- def add_sparkline(...)
1027
- warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
1028
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1029
-
1030
- @writer.add_sparkline(...)
1031
- end
1032
-
1033
796
  # Sets workbook-level properties.
1034
797
  #
1035
- # @param name [Symbol] Workbook property name.
1036
- # @param value [String, Integer, Boolean] Property value.
1037
- # @return [void]
1038
- # @api public
1039
- #: (Symbol name, String | Integer | bool value) -> void
1040
- def workbook_property(...)
1041
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1042
-
1043
- @writer.workbook_property(...)
1044
- end
1045
-
1046
- # Sets or gets the active sheet in the workbook window.
1047
- # If called without arguments on the proxy, marks this sheet as the active sheet.
1048
- #
1049
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#active_sheet=} instead.
1050
- # @param name_or_index [String, Symbol, Integer, nil]
1051
- # @return [String, Symbol, Integer, nil]
1052
- # @api public
1053
- #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1054
- def active_sheet(name_or_index = @sheet_name)
1055
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1056
-
1057
- @writer.active_sheet(name_or_index)
1058
- end
1059
- # @deprecated Use {#active_sheet} instead. Will be removed in 0.2.0.
1060
- alias active_tab active_sheet
1061
-
1062
- # Sets the active worksheet tab in the workbook window.
1063
- #
1064
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
1065
- # @return [String, Symbol, Integer, nil]
1066
- # @api public
1067
- #: (String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1068
- def active_sheet=(name_or_index)
1069
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1070
-
1071
- @writer.active_sheet = name_or_index
1072
- end
1073
- # @deprecated Use {#active_sheet=} instead. Will be removed in 0.2.0.
1074
- alias active_tab= active_sheet=
1075
-
1076
- # Sets or gets the first visible sheet in the tab bar.
1077
- #
1078
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#first_sheet=} instead.
1079
- # @param name_or_index [String, Symbol, Integer, nil]
1080
- # @return [String, Symbol, Integer, nil]
1081
- # @api public
1082
- #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1083
- def first_sheet(name_or_index = @sheet_name)
1084
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1085
-
1086
- @writer.first_sheet(name_or_index)
1087
- end
1088
-
1089
- # Sets the first visible sheet in the tab bar.
1090
- #
1091
- # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
1092
- # @return [String, Symbol, Integer, nil]
1093
- # @api public
1094
- #: (String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1095
- def first_sheet=(name_or_index)
1096
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1097
-
1098
- @writer.first_sheet = name_or_index
1099
- end
1100
-
1101
- # Sets or gets whether sheet tabs are visible in the workbook window.
1102
- #
1103
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_sheet_tabs=} instead.
1104
- # @param visible [Boolean, nil]
1105
- # @return [Boolean, nil]
1106
- # @api public
1107
- #: (?bool? visible) -> bool?
1108
- def show_sheet_tabs(visible = nil)
1109
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1110
-
1111
- @writer.show_sheet_tabs(visible)
1112
- end
1113
-
1114
- # Sets whether sheet tabs are visible in the workbook window.
1115
- #
1116
- # @param visible [Boolean, nil]
1117
- # @return [Boolean, nil]
1118
- # @api public
1119
- #: (bool? visible) -> bool?
1120
- def show_sheet_tabs=(visible)
1121
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1122
-
1123
- @writer.show_sheet_tabs = visible
1124
- end
1125
-
1126
- # Sets or gets the tab ratio between tab bar and horizontal scrollbar (0-1000).
1127
- #
1128
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_ratio=} instead.
1129
- # @param ratio [Integer, nil]
1130
- # @return [Integer, nil]
1131
- # @api public
1132
- #: (?Integer? ratio) -> Integer?
1133
- def tab_ratio(ratio = nil)
1134
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1135
-
1136
- @writer.tab_ratio(ratio)
1137
- end
1138
-
1139
- # Sets the tab ratio between tab bar and horizontal scrollbar (0-1000).
1140
- #
1141
- # @param ratio [Integer, nil]
1142
- # @return [Integer, nil]
1143
- # @api public
1144
- #: (Integer? ratio) -> Integer?
1145
- def tab_ratio=(ratio)
1146
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1147
-
1148
- @writer.tab_ratio = ratio
1149
- end
1150
-
1151
- # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
798
+ # Gets the sheet visibility state (:visible, :hidden, or :very_hidden).
1152
799
  #
1153
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
1154
- # @param new_state [Symbol, nil] The new state.
1155
800
  # @return [Symbol]
1156
801
  # @api public
1157
- #: (?Symbol? new_state) -> Symbol
1158
- def state(new_state = nil)
1159
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1160
-
1161
- @writer.state(new_state)
802
+ #: () -> Symbol
803
+ def state
804
+ @writer.state
1162
805
  end
1163
806
 
1164
807
  # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
@@ -1168,24 +811,19 @@ module Xlsxrb
1168
811
  # @api public
1169
812
  #: (Symbol | String new_state) -> Symbol
1170
813
  def state=(new_state)
1171
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
814
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1172
815
 
1173
816
  @writer.state = new_state
1174
817
  @writer.state
1175
818
  end
1176
819
 
1177
- # Gets or sets the tab color of this worksheet.
820
+ # Gets the tab color of this worksheet.
1178
821
  #
1179
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
1180
- # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
1181
- # @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5).
1182
822
  # @return [String, Hash, nil]
1183
823
  # @api public
1184
- #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
1185
- def tab_color(...)
1186
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1187
-
1188
- @writer.tab_color(...)
824
+ #: () -> (String | Hash[Symbol, untyped] | nil)
825
+ def tab_color
826
+ @writer.tab_color
1189
827
  end
1190
828
 
1191
829
  # Sets the tab color of this worksheet.
@@ -1195,39 +833,22 @@ module Xlsxrb
1195
833
  # @api public
1196
834
  #: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
1197
835
  def tab_color=(spec)
1198
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
836
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1199
837
 
1200
838
  @writer.tab_color = spec
1201
839
  end
1202
840
 
1203
- # Sets a single sheet property.
1204
- #
1205
- # @param name [Symbol, String] Property name.
1206
- # @param value [Object] Property value.
1207
- # @return [void]
1208
- # @api public
1209
- #: (Symbol | String name, untyped value) -> void
1210
- def sheet_property(...)
1211
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1212
-
1213
- @writer.sheet_property(...)
1214
- end
1215
-
1216
- # Sets sheet properties (e.g. tab color, page setup flags). Accepts kwargs or name/value pair.
841
+ # Configures or queries sheet properties.
1217
842
  #
1218
- # @example
1219
- # s.sheet_properties(tab_color: "FF0000")
1220
- #
1221
- # @param name [Symbol, String, Hash, nil] Property name or hash.
1222
- # @param value [Object, nil] Property value.
1223
- # @param opts [Hash] Additional options.
1224
- # @return [void]
843
+ # @param opts [Hash] Keyword options for sheet properties.
844
+ # @return [Elements::SheetProperties, void]
1225
845
  # @api public
1226
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
1227
- def sheet_properties(...)
1228
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
846
+ #: () -> Elements::SheetProperties
847
+ #: (**untyped opts) -> void
848
+ def sheet_properties(**opts)
849
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1229
850
 
1230
- @writer.sheet_properties(...)
851
+ @writer.sheet_properties(**opts)
1231
852
  end
1232
853
 
1233
854
  # Replaces worksheet properties.
@@ -1236,7 +857,7 @@ module Xlsxrb
1236
857
  # @api public
1237
858
  #: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
1238
859
  def sheet_properties=(opts)
1239
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
860
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1240
861
 
1241
862
  @writer.sheet_properties = opts
1242
863
  end
@@ -1247,39 +868,28 @@ module Xlsxrb
1247
868
  # @param name [String] Defined name identifier.
1248
869
  # @param value [Object, nil] Value or formula expression.
1249
870
  # @param hidden [Boolean] Whether the defined name is hidden.
1250
- # @param column [Integer, String, nil] Deprecated alias for columns.
1251
871
  # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
1252
- # @param col [Integer, String, nil] Deprecated alias for column.
1253
- # @param row [Integer, Range, nil] Deprecated alias for rows.
1254
- # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
872
+ # @param rows [Integer, Range, nil] Row or row range (0-based) for coordinate-based reference.
1255
873
  # @param range [String, nil] Cell range reference.
1256
874
  # @param sheet [String, nil] Reference sheet name (defaults to current sheet).
1257
875
  # @param scope [String, Symbol, nil] Scope identifier (:workbook or sheet name).
1258
- # @param local [Boolean] Deprecated alias for scope: :current.
1259
876
  # @return [void]
1260
877
  # @api public
1261
- #: (String name, ?untyped value, ?hidden: bool, ?column: untyped, ?columns: untyped, ?col: untyped, ?row: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?scope: (String | Symbol)?, ?local: bool) -> void
1262
- def defined_name(name, value = nil, hidden: false, column: nil, columns: nil, col: nil, row: nil, rows: nil, range: nil, sheet: nil, scope: nil, local: false)
1263
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1264
-
1265
- warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
1266
- warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
1267
- warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
1268
- warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
1269
- c_arg = column || columns || col
1270
- r_arg = row || rows
878
+ #: (String name, ?untyped value, ?hidden: bool, ?columns: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?scope: (String | Symbol)?) -> void
879
+ def defined_name(name, value = nil, hidden: false, columns: nil, rows: nil, range: nil, sheet: nil, scope: nil)
880
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
881
+
1271
882
  ref_sheet = sheet || @sheet_name
1272
883
  local_sheet = if scope
1273
884
  scope == :workbook ? nil : scope.to_s
1274
- elsif local
1275
- @sheet_name || sheet
1276
- else
1277
- sheet
1278
885
  end
1279
- @writer.defined_name(name, value, sheet: local_sheet, hidden: hidden, columns: c_arg, rows: r_arg, range: range, ref_sheet: ref_sheet)
886
+ @writer.defined_name(name, value, sheet: ref_sheet, scope: local_sheet, hidden: hidden, columns: columns, rows: rows, range: range)
1280
887
  end
1281
888
 
1282
- # Freezes rows and/or columns for scrolling.
889
+ # Configures or queries freeze panes (<pane state="frozen">).
890
+ #
891
+ # When called with no arguments, returns the {Elements::FreezePane} value object or nil.
892
+ # When called with arguments, configures the freeze pane and returns nil.
1283
893
  #
1284
894
  # @example Freeze top row
1285
895
  # s.freeze_pane(row: 1)
@@ -1289,12 +899,12 @@ module Xlsxrb
1289
899
  #
1290
900
  # @param row [Integer, nil] Number of rows to freeze.
1291
901
  # @param column [Integer, String, nil] Number of columns to freeze.
1292
- # @param col [Integer, String, nil] Deprecated alias for column.
1293
- # @return [void]
902
+ # @return [Elements::FreezePane, nil, void]
1294
903
  # @api public
1295
- #: (?row: Integer | nil, ?column: (Integer | String)?, ?col: (Integer | String)?) -> void
904
+ #: () -> Elements::FreezePane?
905
+ #: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
1296
906
  def freeze_pane(...)
1297
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
907
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1298
908
 
1299
909
  @writer.freeze_pane(...)
1300
910
  end
@@ -1304,27 +914,20 @@ module Xlsxrb
1304
914
  # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
1305
915
  # @return [void]
1306
916
  # @api public
1307
- #: (untyped opts) -> void
917
+ #: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
1308
918
  def freeze_pane=(opts)
1309
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
919
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1310
920
 
1311
921
  @writer.freeze_pane = opts
1312
922
  end
1313
923
 
1314
- # Sets or gets the print area range for the sheet.
924
+ # Returns the print area range for this worksheet, or nil if none.
1315
925
  #
1316
- # @param range [String, Object, nil] Range reference.
1317
- # @return [String, nil, void]
926
+ # @return [String, nil]
1318
927
  # @api public
1319
- #: (?untyped range) -> (String | nil | void)
1320
- def print_area(range = OMITTED)
1321
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1322
-
1323
- if range.equal?(OMITTED)
1324
- @writer.print_area
1325
- else
1326
- @writer.print_area(range, sheet: @sheet_name)
1327
- end
928
+ #: () -> String?
929
+ def print_area
930
+ @writer.print_area(sheet: @sheet_name)
1328
931
  end
1329
932
 
1330
933
  # Sets the print area for this worksheet.
@@ -1334,27 +937,29 @@ module Xlsxrb
1334
937
  # @api public
1335
938
  #: (String? range) -> String?
1336
939
  def print_area=(range)
1337
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
940
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1338
941
 
1339
- @writer.print_area(range, sheet: @sheet_name)
1340
- range
942
+ @writer.send(:set_print_area, range, sheet: @sheet_name)
1341
943
  end
1342
944
 
1343
- # Configures or gets repeating title rows and columns for printing.
945
+ # Sets or gets repeating print titles (rows and/or columns) for pagination.
1344
946
  #
1345
- # @param rows [String, Integer, Range, Object, nil] Row range to repeat (e.g. "1:2").
1346
- # @param columns [String, Integer, Symbol, Range, Object, nil] Column range to repeat (e.g. "A:B").
1347
- # @param cols [String, Integer, Symbol, Range, Object, nil] Deprecated alias for columns.
947
+ # When called with no arguments, returns the {Elements::PrintTitles} value object or nil.
948
+ # When called with arguments, updates print titles and returns nil.
949
+ #
950
+ # @param rows [String, Integer, Range, nil] Repeating row range (e.g. "1:2").
951
+ # @param columns [String, Integer, Symbol, Range, nil] Repeating column range (e.g. "A:B").
1348
952
  # @return [Elements::PrintTitles, nil, void]
1349
953
  # @api public
1350
- #: (?rows: untyped, ?columns: untyped, ?cols: untyped) -> (Elements::PrintTitles | nil | void)
1351
- def print_titles(rows: OMITTED, columns: OMITTED, cols: OMITTED)
1352
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
954
+ #: () -> Elements::PrintTitles?
955
+ #: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?) -> void
956
+ def print_titles(rows: nil, columns: nil)
957
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1353
958
 
1354
- if rows.equal?(OMITTED) && columns.equal?(OMITTED) && cols.equal?(OMITTED)
1355
- @writer.print_titles
959
+ if rows.nil? && columns.nil?
960
+ @writer.print_titles(sheet: @sheet_name)
1356
961
  else
1357
- @writer.print_titles(rows: rows, columns: columns, cols: cols, sheet: @sheet_name)
962
+ @writer.print_titles(rows: rows, columns: columns, sheet: @sheet_name)
1358
963
  end
1359
964
  end
1360
965
 
@@ -1365,7 +970,7 @@ module Xlsxrb
1365
970
  # @api public
1366
971
  #: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
1367
972
  def print_titles=(opts)
1368
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
973
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1369
974
 
1370
975
  if opts.nil?
1371
976
  @writer.print_titles = nil
@@ -1384,7 +989,7 @@ module Xlsxrb
1384
989
  # @api public
1385
990
  #: (Integer | String first, ?(Integer | String)? last) -> void
1386
991
  def repeat_rows(first, last = nil)
1387
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
992
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1388
993
 
1389
994
  @writer.repeat_rows(first, last, sheet: @sheet_name)
1390
995
  end
@@ -1397,24 +1002,28 @@ module Xlsxrb
1397
1002
  # @api public
1398
1003
  #: (Integer | String first, ?(Integer | String)? last) -> void
1399
1004
  def repeat_columns(first, last = nil)
1400
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1005
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1401
1006
 
1402
1007
  @writer.repeat_columns(first, last, sheet: @sheet_name)
1403
1008
  end
1404
1009
  # simplecov:enable
1405
1010
 
1406
- # Splits sheet view into panes.
1011
+ # Splits sheet view into panes or queries split pane settings (<pane>).
1012
+ #
1013
+ # When called with no arguments, returns the {Elements::SplitPane} value object or nil.
1014
+ # When called with arguments, configures the split pane and returns nil.
1407
1015
  #
1408
- # @param x_split [Integer] Horizontal split position.
1409
- # @param y_split [Integer] Vertical split position.
1016
+ # @param x_split [Integer, nil] Horizontal split position.
1017
+ # @param y_split [Integer, nil] Vertical split position.
1410
1018
  # @param top_left_cell [String, nil] Top-left visible cell in bottom-right pane.
1411
1019
  # @param active_pane [String, Symbol, nil] Active pane identifier.
1412
1020
  # @param state [String, Symbol, nil] Split state.
1413
- # @return [void]
1021
+ # @return [Elements::SplitPane, nil, void]
1414
1022
  # @api public
1415
- #: (?x_split: Integer, ?y_split: Integer, ?top_left_cell: String?, ?active_pane: (String | Symbol)?, ?state: (String | Symbol)?) -> void
1023
+ #: () -> Elements::SplitPane?
1024
+ #: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
1416
1025
  def split_pane(...)
1417
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1026
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1418
1027
 
1419
1028
  @writer.split_pane(...)
1420
1029
  end
@@ -1424,59 +1033,27 @@ module Xlsxrb
1424
1033
  # @param opts [Elements::SplitPane, Hash, nil] Split pane options.
1425
1034
  # @return [void]
1426
1035
  # @api public
1427
- #: (untyped opts) -> void
1036
+ #: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
1428
1037
  def split_pane=(opts)
1429
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1038
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1430
1039
 
1431
1040
  @writer.split_pane = opts
1432
1041
  end
1433
1042
 
1434
- # simplecov:disable
1435
- # Edge case / untested delegation block
1436
- # Sets workbook structure and window protection.
1437
- #
1438
- # @param opts [Hash] Protection options.
1439
- # @return [void]
1440
- # @api public
1441
- #: (**untyped opts) -> void
1442
- def workbook_protection(...)
1443
- @writer.workbook_protection(...)
1444
- end
1445
-
1446
- # @deprecated Use {#workbook_protection} instead.
1447
- #: (**untyped opts) -> void
1448
- def protect_workbook(...)
1449
- warn "[DEPRECATION] `protect_workbook` is deprecated; use `workbook_protection` instead.", uplevel: 1
1450
- workbook_protection(...)
1451
- end
1452
- # simplecov:enable
1453
-
1454
- # simplecov:disable
1455
- # Edge case / untested delegation block
1456
- # Sets core metadata property.
1043
+ # Sets or queries the active/selected cell on the sheet (<selection>).
1457
1044
  #
1458
- # @param name [Symbol] Property name.
1459
- # @param value [String, Integer, Time] Property value.
1460
- # @return [void]
1461
- # @api public
1462
- #: (Symbol name, String | Integer | Time value) -> void
1463
- def core_property(...)
1464
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1465
-
1466
- @writer.core_property(...)
1467
- end
1468
- # simplecov:enable
1469
-
1470
- # Sets the active/selected cell on the sheet.
1045
+ # When called with no arguments, returns the selection ({Elements::Selection}, Array, or nil).
1046
+ # When called with arguments, updates the selection and returns nil.
1471
1047
  #
1472
- # @param active_cell [String] Cell reference (e.g. "A1") or range (e.g. "A1:D10").
1048
+ # @param active_cell [String, nil] Cell reference (e.g. "A1") or range (e.g. "A1:D10").
1473
1049
  # @param sqref [String, nil] Selection range.
1474
1050
  # @param pane [String, Symbol, nil] Pane identifier.
1475
- # @return [void]
1051
+ # @return [Elements::Selection, Array<Elements::Selection>, nil, void]
1476
1052
  # @api public
1477
- #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
1053
+ #: () -> (Elements::Selection | Array[Elements::Selection])?
1054
+ #: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
1478
1055
  def selection(...)
1479
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1056
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1480
1057
 
1481
1058
  @writer.selection(...)
1482
1059
  end
@@ -1486,21 +1063,17 @@ module Xlsxrb
1486
1063
  # @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
1487
1064
  # @return [void]
1488
1065
  # @api public
1489
- #: (untyped opts) -> void
1066
+ #: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
1490
1067
  def selection=(opts)
1491
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1068
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1492
1069
 
1493
1070
  @writer.selection = opts
1494
1071
  end
1495
1072
 
1496
- # @deprecated Use {#selection} instead.
1497
- #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
1498
- def select_cell(...)
1499
- warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
1500
- selection(...)
1501
- end
1502
-
1503
- # Configures page margins for printing.
1073
+ # Configures or queries page margins for printing (<pageMargins>).
1074
+ #
1075
+ # When called with no arguments, returns the {Elements::PageMargins} value object or nil.
1076
+ # When called with arguments, configures page margins and returns nil.
1504
1077
  #
1505
1078
  # @param left [Float, nil] Left margin in inches.
1506
1079
  # @param right [Float, nil] Right margin in inches.
@@ -1508,37 +1081,42 @@ module Xlsxrb
1508
1081
  # @param bottom [Float, nil] Bottom margin in inches.
1509
1082
  # @param header [Float, nil] Header margin in inches.
1510
1083
  # @param footer [Float, nil] Footer margin in inches.
1511
- # @return [void]
1084
+ # @return [Elements::PageMargins, nil, void]
1512
1085
  # @api public
1086
+ #: () -> Elements::PageMargins?
1513
1087
  #: (?left: Float | nil, ?right: Float | nil, ?top: Float | nil, ?bottom: Float | nil, ?header: Float | nil, ?footer: Float | nil) -> void
1514
1088
  def page_margins(...)
1515
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1089
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1516
1090
 
1517
1091
  @writer.page_margins(...)
1518
1092
  end
1519
1093
 
1520
- # Sets page margins configuration.
1094
+ # Sets or clears page margins configuration.
1521
1095
  #
1522
1096
  # @param opts [Hash, Elements::PageMargins, nil]
1523
1097
  # @return [void]
1524
1098
  # @api public
1525
- #: (untyped opts) -> void
1099
+ #: (Hash[Symbol, untyped] | Elements::PageMargins | nil opts) -> void
1526
1100
  def page_margins=(opts)
1527
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1101
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1528
1102
 
1529
1103
  @writer.page_margins = opts
1530
1104
  end
1531
1105
 
1532
- # Configures page orientation, paper size, and print setup.
1106
+ # Configures or queries page orientation, paper size, and print setup (<pageSetup>).
1107
+ #
1108
+ # When called with no arguments, returns the {Elements::PageSetup} value object.
1109
+ # When called with keyword arguments, updates page setup and returns nil.
1533
1110
  #
1534
1111
  # @param orientation [String, Symbol, nil] "portrait" or "landscape" (or :portrait, :landscape).
1535
1112
  # @param paper_size [Integer, nil] Paper size index (e.g. 9 for A4, 1 for Letter).
1536
1113
  # @param opts [Hash] Additional options (scale, fit_to_width, fit_to_height).
1537
- # @return [void]
1114
+ # @return [Elements::PageSetup, void]
1538
1115
  # @api public
1539
- #: (?orientation: (String | Symbol)?, ?paper_size: Integer | nil, **untyped opts) -> void
1116
+ #: () -> Elements::PageSetup
1117
+ #: (**untyped opts) -> void
1540
1118
  def page_setup(...)
1541
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1119
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1542
1120
 
1543
1121
  @writer.page_setup(...)
1544
1122
  end
@@ -1548,21 +1126,25 @@ module Xlsxrb
1548
1126
  # @param opts [Hash, Elements::PageSetup]
1549
1127
  # @return [void]
1550
1128
  # @api public
1551
- #: (untyped opts) -> void
1129
+ #: (Hash[Symbol, untyped] | Elements::PageSetup opts) -> void
1552
1130
  def page_setup=(opts)
1553
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1131
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1554
1132
 
1555
1133
  @writer.page_setup = opts
1556
1134
  end
1557
1135
 
1558
- # Configures header and footer text for printing.
1136
+ # Configures or queries header and footer text for printing (<headerFooter>).
1137
+ #
1138
+ # When called with no arguments, returns the {Elements::HeaderFooter} value object.
1139
+ # When called with keyword arguments, updates headers and footers and returns nil.
1559
1140
  #
1560
1141
  # @param opts [Hash] Header and footer specifications.
1561
- # @return [void]
1142
+ # @return [Elements::HeaderFooter, void]
1562
1143
  # @api public
1144
+ #: () -> Elements::HeaderFooter
1563
1145
  #: (**untyped opts) -> void
1564
1146
  def header_footer(...)
1565
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1147
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1566
1148
 
1567
1149
  @writer.header_footer(...)
1568
1150
  end
@@ -1572,25 +1154,25 @@ module Xlsxrb
1572
1154
  # @param opts [Hash, Elements::HeaderFooter]
1573
1155
  # @return [void]
1574
1156
  # @api public
1575
- #: (untyped opts) -> void
1157
+ #: (Hash[Symbol, untyped] | Elements::HeaderFooter opts) -> void
1576
1158
  def header_footer=(opts)
1577
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1159
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1578
1160
 
1579
1161
  @writer.header_footer = opts
1580
1162
  end
1581
1163
 
1582
- # Configures print options (e.g. gridlines, headings).
1164
+ # Configures or gets print options (e.g. gridlines, headings).
1165
+ # Configures or queries print options.
1583
1166
  #
1584
- # @param name [Symbol, String, Hash, nil] Print option name or hash.
1585
- # @param value [Object, nil] Print option value.
1586
1167
  # @param opts [Hash] Additional options.
1587
- # @return [void]
1168
+ # @return [Elements::PrintOptions, void]
1588
1169
  # @api public
1589
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
1590
- def print_options(...)
1591
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1170
+ #: () -> Elements::PrintOptions
1171
+ #: (**untyped opts) -> void
1172
+ def print_options(**opts)
1173
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1592
1174
 
1593
- @writer.print_options(...)
1175
+ @writer.print_options(**opts)
1594
1176
  end
1595
1177
 
1596
1178
  # Replaces print options.
@@ -1599,52 +1181,23 @@ module Xlsxrb
1599
1181
  # @api public
1600
1182
  #: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
1601
1183
  def print_options=(opts)
1602
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1184
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1603
1185
 
1604
1186
  @writer.print_options = opts
1605
1187
  end
1606
1188
 
1607
- # simplecov:disable
1608
- # Edge case / untested delegation block
1609
- # Sets document metadata properties (core, app, custom).
1610
- #
1611
- # @param core [Hash, nil] Core properties (title, creator, subject, etc.).
1612
- # @param app [Hash, nil] App properties (company, manager).
1613
- # @param custom [Hash, nil] Custom properties.
1614
- # @return [void]
1615
- # @api public
1616
- #: (?core: Hash[untyped, untyped]?, ?app: Hash[untyped, untyped]?, ?custom: Hash[untyped, untyped]?) -> void
1617
- def properties(...)
1618
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1619
-
1620
- @writer.properties(...)
1621
- end
1622
- # simplecov:enable
1623
-
1624
- # simplecov:disable
1625
- # Edge case / untested delegation block
1626
- # Sets app metadata property.
1189
+ # Sets or queries sheet-level protection with optional password hashing (<sheetProtection>).
1627
1190
  #
1628
- # @param name [Symbol] Property name.
1629
- # @param value [String, Integer, Time] Property value.
1630
- # @return [void]
1631
- # @api public
1632
- #: (Symbol name, String | Integer | Time value) -> void
1633
- def app_property(...)
1634
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1635
-
1636
- @writer.app_property(...)
1637
- end
1638
- # simplecov:enable
1639
-
1640
- # Sets sheet-level protection with optional password hashing.
1191
+ # When called with no arguments, returns the {Elements::SheetProtection} value object or nil.
1192
+ # When called with keyword arguments, sets sheet protection and returns nil.
1641
1193
  #
1642
1194
  # @param opts [Hash] Protection options.
1643
- # @return [void]
1195
+ # @return [Elements::SheetProtection, nil, void]
1644
1196
  # @api public
1197
+ #: () -> Elements::SheetProtection?
1645
1198
  #: (**untyped opts) -> void
1646
1199
  def sheet_protection(...)
1647
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1200
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1648
1201
 
1649
1202
  @writer.sheet_protection(...)
1650
1203
  end
@@ -1654,102 +1207,74 @@ module Xlsxrb
1654
1207
  # @param opts [Elements::SheetProtection, Hash, Boolean, nil]
1655
1208
  # @return [void]
1656
1209
  # @api public
1657
- #: (untyped opts) -> void
1210
+ #: (Elements::SheetProtection | Hash[Symbol, untyped] | bool | nil opts) -> void
1658
1211
  def sheet_protection=(opts)
1659
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1212
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1660
1213
 
1661
1214
  @writer.sheet_protection = opts
1662
1215
  end
1663
1216
 
1664
- # @deprecated Use {#sheet_protection} instead.
1665
- #: (**untyped opts) -> void
1666
- def protect_sheet(...)
1667
- warn "[DEPRECATION] `protect_sheet` is deprecated; use `sheet_protection` instead.", uplevel: 1
1668
- sheet_protection(...)
1669
- end
1670
-
1671
- # simplecov:disable
1672
- # Edge case / untested delegation block
1673
- # Sets custom metadata property.
1217
+ # Returns column configurations defined for this worksheet.
1674
1218
  #
1675
- # @param name [String] Property name.
1676
- # @param value [String, Integer, Float, Boolean, Time] Property value.
1677
- # @param type [Symbol] Value type.
1678
- # @return [void]
1219
+ # @return [Array<Elements::Column>]
1679
1220
  # @api public
1680
- #: (String name, String | Integer | Float | bool | Time value, ?type: ::Symbol) -> void
1681
- def custom_property(...)
1682
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1221
+ #: () -> Array[Elements::Column]
1222
+ def columns
1223
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1683
1224
 
1684
- @writer.custom_property(...)
1225
+ @writer.columns
1685
1226
  end
1686
- # simplecov:enable
1687
1227
 
1688
1228
  # Inserts an image into the sheet.
1689
1229
  #
1690
1230
  # @param file_data [String] Binary image data or file content.
1691
1231
  # @param ext [String] Image extension ("png", "jpeg", etc.).
1692
1232
  # @param from_column [Integer, nil] Starting column index (0-based).
1693
- # @param from_col [Integer, nil] Deprecated alias for from_column.
1694
1233
  # @param from_row [Integer] Starting row index (0-based).
1695
1234
  # @param to_column [Integer, nil] Ending column index (0-based).
1696
- # @param to_col [Integer, nil] Deprecated alias for to_column.
1697
1235
  # @param to_row [Integer] Ending row index (0-based).
1698
1236
  # @param opts [Hash] Additional anchor and sizing options.
1699
1237
  # @return [void]
1700
1238
  # @api public
1701
- #: (String file_data, ?ext: String, ?from_column: Integer?, ?from_col: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_col: Integer?, ?to_row: Integer, **untyped opts) -> void
1239
+ #: (String file_data, ?ext: String, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
1702
1240
  def image(...)
1703
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1241
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1704
1242
 
1705
1243
  @writer.image(...)
1706
1244
  end
1707
1245
 
1708
- # Configures the worksheet background image (<picture>).
1709
- #
1710
- # @example Set background image from binary data
1711
- # sheet.background_image(png_bytes, ext: "png")
1246
+ # Gets the worksheet background image (<picture>).
1712
1247
  #
1713
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
1714
- # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
1715
- # @param ext [String, nil] Image extension.
1716
- # @param opts [Hash] Additional options.
1717
- # @return [Hash, nil]
1248
+ # @return [Elements::BackgroundImage, nil]
1718
1249
  # @api public
1719
- #: (?untyped file_data, ?ext: String?, **untyped opts) -> Hash[Symbol, untyped]?
1720
- def background_image(...)
1721
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1722
-
1723
- @writer.background_image(...)
1250
+ #: () -> Elements::BackgroundImage?
1251
+ def background_image
1252
+ @writer.background_image
1724
1253
  end
1725
- # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1726
- alias background_picture background_image
1727
- # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1728
- alias picture background_image
1729
1254
 
1255
+ # Sets the worksheet background image (<picture>).
1256
+ #
1257
+ # @param val [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
1258
+ # @return [untyped]
1259
+ # @api public
1730
1260
  #: (untyped val) -> untyped
1731
1261
  def background_image=(val)
1732
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1262
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1733
1263
 
1734
1264
  @writer.background_image = val
1735
1265
  end
1736
- # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1737
- alias background_picture= background_image=
1738
- # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1739
- alias picture= background_image=
1740
1266
 
1741
- # Configures sheet view settings (zoom scale, grid lines visibility).
1267
+ # Configures or gets sheet view settings (zoom scale, grid lines visibility).
1742
1268
  #
1743
- # @param name [Symbol, String, Hash, nil] View setting name or hash.
1744
- # @param value [Object, nil] View setting value.
1745
1269
  # @param opts [Hash] Additional options.
1746
- # @return [void]
1270
+ # @return [Elements::SheetView, void]
1747
1271
  # @api public
1748
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
1749
- def sheet_view(...)
1750
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1272
+ #: () -> Elements::SheetView
1273
+ #: (**untyped opts) -> void
1274
+ def sheet_view(**opts)
1275
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1751
1276
 
1752
- @writer.sheet_view(...)
1277
+ @writer.sheet_view(**opts)
1753
1278
  end
1754
1279
 
1755
1280
  # Replaces sheet view properties.
@@ -1758,23 +1283,22 @@ module Xlsxrb
1758
1283
  # @api public
1759
1284
  #: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
1760
1285
  def sheet_view=(opts)
1761
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1286
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1762
1287
 
1763
1288
  @writer.sheet_view = opts
1764
1289
  end
1765
1290
 
1766
- # Configures sheet format properties (e.g. default_row_height, default_col_width).
1291
+ # Configures or gets sheet format properties (e.g. default_row_height, default_column_width).
1767
1292
  #
1768
- # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
1769
- # @param value [Object, nil] Property value when name is provided.
1770
1293
  # @param opts [Hash] Keyword arguments for sheet format properties.
1771
- # @return [Hash[Symbol, untyped]]
1294
+ # @return [Elements::SheetFormat, void]
1772
1295
  # @api public
1773
- #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
1774
- def sheet_format(name = nil, value = nil, **opts)
1775
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1296
+ #: () -> Elements::SheetFormat
1297
+ #: (**untyped opts) -> void
1298
+ def sheet_format(**opts)
1299
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1776
1300
 
1777
- @writer.sheet_format(name, value, **opts)
1301
+ @writer.sheet_format(**opts)
1778
1302
  end
1779
1303
 
1780
1304
  # Replaces sheet format properties.
@@ -1783,7 +1307,7 @@ module Xlsxrb
1783
1307
  # @api public
1784
1308
  #: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
1785
1309
  def sheet_format=(opts)
1786
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1310
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1787
1311
 
1788
1312
  @writer.sheet_format = opts
1789
1313
  end
@@ -1797,17 +1321,10 @@ module Xlsxrb
1797
1321
  # @api public
1798
1322
  #: (Integer row_index) -> void
1799
1323
  def row_break(...)
1800
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1324
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1801
1325
 
1802
1326
  @writer.row_break(...)
1803
1327
  end
1804
-
1805
- # @deprecated Use {#row_break} instead.
1806
- #: (Integer row_num) -> void
1807
- def page_break_row(...)
1808
- warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
1809
- row_break(...)
1810
- end
1811
1328
  # simplecov:enable
1812
1329
 
1813
1330
  # simplecov:disable
@@ -1819,17 +1336,10 @@ module Xlsxrb
1819
1336
  # @api public
1820
1337
  #: (Integer | String | Symbol col) -> void
1821
1338
  def column_break(...)
1822
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1339
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1823
1340
 
1824
1341
  @writer.column_break(...)
1825
1342
  end
1826
-
1827
- # @deprecated Use {#column_break} instead.
1828
- #: (Integer | String | Symbol col_index) -> void
1829
- def page_break_col(...)
1830
- warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
1831
- column_break(...)
1832
- end
1833
1343
  # simplecov:enable
1834
1344
 
1835
1345
  # Adds a protected range to the sheet.
@@ -1842,12 +1352,10 @@ module Xlsxrb
1842
1352
  # @api public
1843
1353
  #: (String name, String sqref, ?password: String?, **untyped opts) -> void
1844
1354
  def protected_range(...)
1845
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1355
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1846
1356
 
1847
1357
  @writer.protected_range(...)
1848
1358
  end
1849
- # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
1850
- alias add_protected_range protected_range
1851
1359
 
1852
1360
  # Adds a cell watch to the sheet.
1853
1361
  #
@@ -1856,12 +1364,10 @@ module Xlsxrb
1856
1364
  # @api public
1857
1365
  #: (String ref) -> void
1858
1366
  def cell_watch(...)
1859
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1367
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1860
1368
 
1861
1369
  @writer.cell_watch(...)
1862
1370
  end
1863
- # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
1864
- alias add_cell_watch cell_watch
1865
1371
 
1866
1372
  # Adds an ignored error entry to the sheet.
1867
1373
  #
@@ -1871,46 +1377,28 @@ module Xlsxrb
1871
1377
  # @api public
1872
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
1873
1379
  def ignored_error(...)
1874
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1380
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1875
1381
 
1876
1382
  @writer.ignored_error(...)
1877
1383
  end
1878
1384
 
1879
- # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1880
- #: (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
1881
- def ignore_error(...)
1882
- warn "[DEPRECATION] #ignore_error is deprecated; use #ignored_error instead.", uplevel: 1
1883
- ignored_error(...)
1884
- end
1885
-
1886
- # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1887
- #: (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
1888
- def add_ignored_error(...)
1889
- warn "[DEPRECATION] #add_ignored_error is deprecated; use #ignored_error instead.", uplevel: 1
1890
- ignored_error(...)
1891
- end
1892
-
1893
1385
  # Returns the ignored error entries configured for this sheet.
1894
1386
  #
1895
- # @return [Array<Hash[Symbol, untyped]>]
1387
+ # @return [Array<Elements::IgnoredError>]
1896
1388
  # @api public
1897
- #: () -> Array[Hash[Symbol, untyped]]
1389
+ #: () -> Array[Elements::IgnoredError]
1898
1390
  def ignored_errors
1899
1391
  @writer.ignored_errors
1900
1392
  end
1901
1393
 
1902
- # Gets or sets phonetic (furigana) guide properties for the sheet.
1394
+ # Gets phonetic (furigana) guide properties for the sheet.
1903
1395
  #
1904
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
1396
+ # @return [Elements::PhoneticProperties, nil]
1905
1397
  # @api public
1906
- #: (?untyped spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> (Elements::PhoneticProperties | Hash[Symbol, untyped] | nil)
1907
- def phonetic_properties(...)
1908
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1909
-
1910
- @writer.phonetic_properties(...)
1398
+ #: () -> Elements::PhoneticProperties?
1399
+ def phonetic_properties
1400
+ @writer.phonetic_properties
1911
1401
  end
1912
- # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
1913
- alias phonetic_pr phonetic_properties
1914
1402
 
1915
1403
  # Sets phonetic (furigana) guide properties for the sheet.
1916
1404
  #
@@ -1919,24 +1407,18 @@ module Xlsxrb
1919
1407
  # @api public
1920
1408
  #: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
1921
1409
  def phonetic_properties=(spec)
1922
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1410
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1923
1411
 
1924
1412
  @writer.phonetic_properties = spec
1925
1413
  end
1926
- # @deprecated Use {#phonetic_properties=} instead. Will be removed in 0.2.0.
1927
- alias phonetic_pr= phonetic_properties=
1928
1414
 
1929
- # Sets or gets the internal code name of the worksheet.
1415
+ # Gets the internal code name of the worksheet.
1930
1416
  #
1931
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
1932
- # @param val [String, Symbol, nil] The code name.
1933
1417
  # @return [String, nil]
1934
1418
  # @api public
1935
- #: (?String | Symbol | nil val) -> String?
1936
- def code_name(...)
1937
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1938
-
1939
- @writer.code_name(...)
1419
+ #: () -> String?
1420
+ def code_name
1421
+ @writer.code_name
1940
1422
  end
1941
1423
 
1942
1424
  # Sets the internal code name of the worksheet.
@@ -1946,36 +1428,18 @@ module Xlsxrb
1946
1428
  # @api public
1947
1429
  #: (String | Symbol | nil val) -> String?
1948
1430
  def code_name=(val)
1949
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1431
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1950
1432
 
1951
1433
  @writer.code_name = val
1952
1434
  end
1953
1435
 
1954
- # Configures whether page setup fits content to page width/height.
1955
- # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
1436
+ # Returns whether page setup fits content to page width/height.
1956
1437
  #
1957
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fit_to_page=} or {#page_setup} with :fit_to_width/:fit_to_height instead.
1958
- # @param enabled [Boolean, nil] Whether to fit to page.
1959
- # @param width [Integer, nil] Pages wide to fit to.
1960
- # @param height [Integer, nil] Pages tall to fit to.
1961
- # @return [Boolean, void]
1962
- # @api public
1963
- #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
1964
- def fit_to_page(enabled = OMITTED, width: nil, height: nil)
1965
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1966
-
1967
- @writer.fit_to_page(enabled, width: width, height: height)
1968
- end
1969
-
1970
- # @deprecated Use {#fit_to_page} instead. Will be removed in 0.2.0.
1971
1438
  # @return [Boolean]
1972
1439
  # @api public
1973
1440
  #: () -> bool
1974
1441
  def fit_to_page?
1975
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1976
-
1977
- warn "[Xlsxrb DEPRECATION] fit_to_page? is deprecated; use fit_to_page instead.", uplevel: 1
1978
- @writer.fit_to_page
1442
+ @writer.fit_to_page?
1979
1443
  end
1980
1444
 
1981
1445
  # Sets whether page setup fits content to page width/height.
@@ -1983,25 +1447,20 @@ module Xlsxrb
1983
1447
  # @param enabled [Boolean, nil] Whether to fit to page.
1984
1448
  # @return [Boolean]
1985
1449
  # @api public
1986
- #: (bool? enabled) -> bool?
1450
+ #: (bool? enabled) -> bool??
1987
1451
  def fit_to_page=(enabled)
1988
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1452
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
1989
1453
 
1990
1454
  @writer.fit_to_page = enabled
1991
1455
  end
1992
1456
 
1993
- # Configures worksheet calculation properties (<sheetCalcPr>).
1457
+ # Gets worksheet calculation properties (<sheetCalcPr>).
1994
1458
  #
1995
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
1996
- # @param spec [Hash, nil] Calculation properties hash.
1997
- # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
1998
- # @return [Hash, nil]
1459
+ # @return [Elements::SheetCalcProperties, nil]
1999
1460
  # @api public
2000
- #: (?untyped spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2001
- def sheet_calc_properties(...)
2002
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
2003
-
2004
- @writer.sheet_calc_properties(...)
1461
+ #: () -> Elements::SheetCalcProperties?
1462
+ def sheet_calc_properties
1463
+ @writer.sheet_calc_properties
2005
1464
  end
2006
1465
 
2007
1466
  # Sets worksheet calculation properties (<sheetCalcPr>).
@@ -2011,37 +1470,20 @@ module Xlsxrb
2011
1470
  # @api public
2012
1471
  #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2013
1472
  def sheet_calc_properties=(spec)
2014
- raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1473
+ raise inactive_sheet_error if @writer.current_sheet != @sheet_name
2015
1474
 
2016
1475
  @writer.sheet_calc_properties = spec
2017
1476
  end
2018
1477
 
2019
- # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2020
- #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2021
- def sheet_calc_pr(...)
2022
- warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2023
- sheet_calc_properties(...)
2024
- end
2025
-
2026
- # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2027
- #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2028
- def calc_pr(...)
2029
- warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2030
- sheet_calc_properties(...)
2031
- end
1478
+ private
2032
1479
 
2033
- # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2034
- #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2035
- def sheet_calc_pr=(spec)
2036
- warn "[DEPRECATION] #sheet_calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2037
- self.sheet_calc_properties = spec
2038
- end
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)
2039
1485
 
2040
- # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2041
- #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2042
- def calc_pr=(spec)
2043
- warn "[DEPRECATION] #calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2044
- self.sheet_calc_properties = spec
1486
+ Error.new("Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet.")
2045
1487
  end
2046
1488
  end
2047
1489
 
@@ -2060,19 +1502,18 @@ module Xlsxrb
2060
1502
  #
2061
1503
  # @param name [String, nil] Sheet name (max 31 characters).
2062
1504
  # @param state [Symbol, String, nil] Sheet visibility state (:visible, :hidden, :very_hidden).
2063
- # @param tab_color [String, Hash, nil] Tab color hex string or color hash.
2064
- # @param code_name [String, nil] VBA code name.
2065
- # @param hidden [Boolean, nil] Deprecated alias for state: :hidden.
1505
+ # @param tab_color [String, Hash, Symbol, nil] Tab color hex string (e.g. "FF0000") or hash options.
1506
+ # @param code_name [String, Symbol, nil] Internal VBA code name of the sheet.
2066
1507
  # @param opts [Hash] Sheet-level configuration.
2067
1508
  # @yield [sheet_proxy]
2068
1509
  # @yieldparam sheet_proxy [WorksheetProxy] The streaming sheet proxy.
2069
1510
  # @return [String] The sheet name.
2070
1511
  # @api public
2071
- #: (?String? name, ?state: (Symbol | String)?, ?tab_color: untyped, ?code_name: String?, ?hidden: bool?, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
2072
- def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, hidden: nil, **opts)
1512
+ #: (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
1513
+ def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, **opts)
2073
1514
  sheet_count = @sheets.size + (@current_sheet ? 1 : 0)
2074
1515
  name ||= "Sheet#{sheet_count + 1}"
2075
- raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters (Excel limitation)" if @strict_excel_mode && name.length > 31
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
2076
1517
  raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet.forbidden_name_chars)
2077
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?("'"))
2078
1519
  raise ArgumentError, "Sheet name '#{name}' is reserved by Excel (Excel limitation)" if @strict_excel_mode && name.casecmp?("History")
@@ -2083,11 +1524,9 @@ module Xlsxrb
2083
1524
 
2084
1525
  active = opts.delete(:active)
2085
1526
  state = opts.delete(:state) if opts.key?(:state)
2086
- hidden = opts.delete(:hidden) if opts.key?(:hidden)
1527
+ hidden = opts.delete(:hidden)
2087
1528
  code_name = opts.delete(:code_name) if opts.key?(:code_name)
2088
1529
  tab_color = opts.delete(:tab_color) if opts.key?(:tab_color)
2089
-
2090
- warn "[Xlsxrb DEPRECATION] sheet keyword hidden: is deprecated; use state: :hidden instead.", uplevel: 1 unless hidden.nil?
2091
1530
  state ||= :hidden if hidden
2092
1531
  state ||= :visible
2093
1532
  state = state.to_sym
@@ -2100,14 +1539,21 @@ module Xlsxrb
2100
1539
  end
2101
1540
  self.tab_color = tab_color if tab_color
2102
1541
  self.code_name = code_name if code_name
2103
- opts.each { |k, v| sheet_properties(k, v) }
1542
+ sheet_properties(**opts) unless opts.empty?
2104
1543
 
2105
1544
  yield WorksheetProxy.new(self, @current_sheet) if block_given?
2106
1545
  @current_sheet
2107
1546
  end
2108
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
+
2109
1552
  # Returns a WorksheetProxy for the current or named sheet.
2110
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
+ #
2111
1557
  # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
2112
1558
  # @yield [proxy]
2113
1559
  # @yieldparam proxy [WorksheetProxy]
@@ -2123,6 +1569,7 @@ module Xlsxrb
2123
1569
  else
2124
1570
  name_or_index.to_s
2125
1571
  end
1572
+ Deprecation.warn(UNKNOWN_SHEET_MESSAGE) unless sheet_names.include?(target_name)
2126
1573
  proxy = WorksheetProxy.new(self, target_name)
2127
1574
  yield proxy if block_given?
2128
1575
  proxy
@@ -2142,10 +1589,13 @@ module Xlsxrb
2142
1589
  @current_row_buffer = String.new(capacity: 65_536)
2143
1590
  @current_sheet_io = StringIO.new(@current_row_buffer)
2144
1591
  date1904 = @workbook_properties&.[](:date1904) ? true : false
2145
- @current_row_writer = Ooxml::WorksheetWriter.new(@current_sheet_io, date1904: date1904, escape_formulas: @escape_formulas)
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
2146
1595
  @current_row_writer.instance_variable_set(:@started, true)
2147
1596
 
2148
1597
  @current_columns = []
1598
+ @current_column_style_names = {} # column index => style name, for date style variants
2149
1599
  @current_charts = []
2150
1600
  @current_hyperlinks = []
2151
1601
  @current_auto_filter = nil
@@ -2222,7 +1672,9 @@ module Xlsxrb
2222
1672
  end
2223
1673
 
2224
1674
  date1904 = @workbook_properties&.[](:date1904) ? true : false
2225
- @current_row_writer = Ooxml::WorksheetWriter.new(zip_io, date1904: date1904, escape_formulas: @escape_formulas)
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
2226
1678
  @current_row_writer.start(
2227
1679
  columns: @current_columns,
2228
1680
  sheet_properties: @current_sheet_properties.empty? ? nil : @current_sheet_properties,
@@ -2246,29 +1698,20 @@ module Xlsxrb
2246
1698
  # @param custom_height [Boolean] Whether custom row height is set.
2247
1699
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
2248
1700
  # @param collapsed [Boolean] Whether the row is collapsed.
2249
- # @param styles [String, Symbol, Array, Hash, nil] Deprecated. Use cell_styles: instead.
2250
- # @param style [Integer, Symbol, String, Hash, nil] Deprecated. Use row_style: instead.
2251
1701
  # @return [void]
2252
1702
  # @api public
2253
- #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?styles: untyped, ?style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
2254
- def row(values, cell_styles: nil, row_style: nil, styles: nil, style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
1703
+ #: (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
1704
+ def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
2255
1705
  sheet if @current_sheet.nil?
2256
1706
 
2257
- if styles
2258
- warn "[DEPRECATION] StreamWriter#row keyword :styles is deprecated; use :cell_styles instead.", uplevel: 1
2259
- cell_styles ||= styles
2260
- end
2261
- if style
2262
- warn "[DEPRECATION] StreamWriter#row keyword :style is deprecated; use :row_style instead.", uplevel: 1
2263
- row_style ||= style
2264
- end
2265
-
2266
1707
  row_index = @current_row_index
2267
1708
  DslHelpers.validate_row_bounds!(row_index, height, strict_excel_mode: @strict_excel_mode)
2268
1709
  @current_row_index += 1
2269
1710
 
2270
1711
  values = DslHelpers.normalize_row_values(values)
2271
1712
  cell_styles = DslHelpers.normalize_row_styles(cell_styles)
1713
+ check_style_names!(cell_styles) if cell_styles
1714
+ check_style_name!(row_style)
2272
1715
 
2273
1716
  if @current_charts && !@current_charts.empty?
2274
1717
  @current_cells ||= {}
@@ -2285,11 +1728,14 @@ module Xlsxrb
2285
1728
 
2286
1729
  row_style_id = if row_style.is_a?(Hash)
2287
1730
  inline_name = "__inline_row_#{row_style.hash}"
2288
- self.style(inline_name, **row_style) unless @style_name_to_id.key?(inline_name)
1731
+ style(inline_name, **row_style) unless @style_name_to_id.key?(inline_name)
2289
1732
  @style_name_to_id[inline_name]
2290
1733
  else
2291
1734
  row_style
2292
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
2293
1739
 
2294
1740
  effective_outline = outline_level || @current_row_outline_level
2295
1741
  effective_collapsed = collapsed || @current_row_collapsed
@@ -2309,8 +1755,6 @@ module Xlsxrb
2309
1755
  @current_row_writer.write_row_values(row_index, values, styles: cell_styles, style_map: @style_name_to_id, sst: @sst, sst_index: @sst_index, attrs: attrs)
2310
1756
  start_sheet_entry if !@sheet_entry_started && @current_row_buffer.bytesize >= 65_536
2311
1757
  end
2312
- # @deprecated Use {#row} instead. Will be removed in 0.2.0.
2313
- alias add_row row
2314
1758
 
2315
1759
  # Appends a row to the worksheet and returns self for chaining.
2316
1760
  #
@@ -2328,9 +1772,6 @@ module Xlsxrb
2328
1772
 
2329
1773
  # Advances the row cursor by count without writing empty row elements.
2330
1774
  #
2331
- # @example Skip one row
2332
- # w.skip_row
2333
- #
2334
1775
  # @example Skip multiple rows
2335
1776
  # w.skip_rows(3)
2336
1777
  #
@@ -2343,9 +1784,8 @@ module Xlsxrb
2343
1784
 
2344
1785
  sheet if @current_sheet.nil?
2345
1786
  @current_row_index += count
1787
+ nil
2346
1788
  end
2347
- # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
2348
- alias skip_row skip_rows
2349
1789
 
2350
1790
  # Sets column formatting and properties for one or multiple columns.
2351
1791
  #
@@ -2364,7 +1804,9 @@ module Xlsxrb
2364
1804
  raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
2365
1805
 
2366
1806
  sheet if @current_sheet.nil?
1807
+ warn_late_sheet_setting("column")
2367
1808
 
1809
+ DslHelpers.check_style_name!(style, @style_name_to_id)
2368
1810
  style_id = if style.is_a?(Hash)
2369
1811
  inline_name = "__inline_col_#{style.hash}"
2370
1812
  style(inline_name, **style) unless @style_name_to_id.key?(inline_name)
@@ -2374,7 +1816,18 @@ module Xlsxrb
2374
1816
  else
2375
1817
  style
2376
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
2377
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
2378
1831
  existing = @current_columns.find { |c| c[:index] == idx }
2379
1832
  if existing
2380
1833
  existing[:width] = width unless width.nil?
@@ -2402,22 +1855,20 @@ module Xlsxrb
2402
1855
  nil
2403
1856
  end
2404
1857
 
2405
- # Returns column configurations defined for the current worksheet.
1858
+ # Returns column configurations defined for the active worksheet.
2406
1859
  #
2407
1860
  # @return [Array<Elements::Column>]
2408
1861
  # @api public
2409
1862
  #: () -> Array[Elements::Column]
2410
1863
  def columns
2411
- sheet if @current_sheet.nil?
1864
+ ensure_sheet_started!
2412
1865
  @current_columns.map do |c|
2413
1866
  if c.is_a?(Elements::Column)
2414
1867
  c
2415
1868
  else
2416
1869
  idx = c[:index]
2417
1870
  style_idx = c[:style] || c[:style_index]
2418
- unmapped = c.except(:index, :width, :hidden, :custom_width, :outline_level, :style, :style_index)
2419
- unmapped[:collapsed] = true if c[:collapsed]
2420
- unmapped[:best_fit] = true if c[:best_fit]
1871
+ unmapped = c.except(:index, :width, :hidden, :custom_width, :outline_level, :style, :style_index, :collapsed, :best_fit)
2421
1872
  Elements::Column.new(
2422
1873
  index: idx,
2423
1874
  width: c[:width],
@@ -2425,6 +1876,8 @@ module Xlsxrb
2425
1876
  custom_width: c[:custom_width] ? true : false,
2426
1877
  outline_level: c[:outline_level],
2427
1878
  style_index: style_idx,
1879
+ collapsed: c[:collapsed] ? true : false,
1880
+ best_fit: c[:best_fit] ? true : false,
2428
1881
  unmapped_data: unmapped
2429
1882
  )
2430
1883
  end
@@ -2451,12 +1904,6 @@ module Xlsxrb
2451
1904
  def group_columns(index, level: 1, collapsed: false, hidden: false, width: nil, style: nil)
2452
1905
  column(index, outline_level: level, collapsed: collapsed, hidden: hidden, width: width, style: style)
2453
1906
  end
2454
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2455
- alias group_column group_columns
2456
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2457
- alias group_cols group_columns
2458
- # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2459
- alias group_col group_columns
2460
1907
 
2461
1908
  # Groups multiple rows with outline hierarchy with a block.
2462
1909
  #
@@ -2491,11 +1938,13 @@ module Xlsxrb
2491
1938
  @current_row_collapsed = prev_collapsed
2492
1939
  @current_row_hidden = prev_hidden
2493
1940
  end
1941
+ nil
2494
1942
  end
2495
- # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
2496
- alias group_row group_rows
2497
1943
 
2498
- # Configures worksheet-level outline and grouping view properties.
1944
+ # Configures or queries worksheet-level outline and grouping view properties.
1945
+ #
1946
+ # When called with no arguments, returns the outline properties Hash.
1947
+ # When called with arguments, updates outline properties and returns nil.
2499
1948
  #
2500
1949
  # @example Show summary row below detail rows
2501
1950
  # sheet.outline_properties(summary_below: true, summary_right: true)
@@ -2503,22 +1952,22 @@ module Xlsxrb
2503
1952
  # @param summary_below [Boolean, nil] Flag indicating if summary rows appear below detail rows.
2504
1953
  # @param summary_right [Boolean, nil] Flag indicating if summary columns appear to the right of detail columns.
2505
1954
  # @param show_outline_symbols [Boolean, nil] Flag indicating whether outline symbols are visible.
2506
- # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
2507
1955
  # @param apply_styles [Boolean, nil] Flag indicating whether automatic styles apply to outlines.
2508
1956
  # @param opts [Hash] Additional options.
2509
1957
  # @return [Hash<Symbol, untyped>, void]
2510
1958
  # @api public
2511
- #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> (Hash[Symbol, untyped] | void)
2512
- def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, show_symbols: nil, apply_styles: nil, **opts)
1959
+ #: () -> Hash[Symbol, untyped]
1960
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
1961
+ def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, apply_styles: nil, **opts)
2513
1962
  sheet if @current_sheet.nil?
2514
- 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? && show_symbols.nil? && apply_styles.nil? && opts.empty?
1963
+ warn_late_sheet_setting("outline_properties") unless summary_below.nil? && summary_right.nil? && show_outline_symbols.nil? && apply_styles.nil? && opts.empty?
1964
+
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?
2515
1966
 
2516
- warn "[Xlsxrb DEPRECATION] outline_properties keyword show_symbols: is deprecated; use show_outline_symbols: instead.", uplevel: 1 unless show_symbols.nil?
2517
1967
  props = (@current_sheet_properties[:outline_properties] || {}).dup
2518
1968
  props[:summary_below] = summary_below unless summary_below.nil?
2519
1969
  props[:summary_right] = summary_right unless summary_right.nil?
2520
- symbols = show_outline_symbols.nil? ? show_symbols : show_outline_symbols
2521
- props[:show_outline_symbols] = symbols unless symbols.nil?
1970
+ props[:show_outline_symbols] = show_outline_symbols unless show_outline_symbols.nil?
2522
1971
  props[:apply_styles] = apply_styles unless apply_styles.nil?
2523
1972
  props.merge!(opts)
2524
1973
  @current_sheet_properties[:outline_properties] = props
@@ -2526,8 +1975,6 @@ module Xlsxrb
2526
1975
  @current_sheet_properties[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
2527
1976
  nil
2528
1977
  end
2529
- # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
2530
- alias outline_pr outline_properties
2531
1978
 
2532
1979
  # Sets worksheet outline and grouping view properties.
2533
1980
  #
@@ -2536,11 +1983,11 @@ module Xlsxrb
2536
1983
  # @api public
2537
1984
  #: (Hash[Symbol, untyped] opts) -> void
2538
1985
  def outline_properties=(opts)
1986
+ sheet if @current_sheet.nil?
2539
1987
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
2540
1988
  outline_properties(**h)
2541
1989
  nil
2542
1990
  end
2543
- alias outline_pr= outline_properties=
2544
1991
 
2545
1992
  # Adds a chart to the current worksheet.
2546
1993
  #
@@ -2557,7 +2004,7 @@ module Xlsxrb
2557
2004
  options = options.merge(type: type) if type
2558
2005
  if block_given?
2559
2006
  builder = ChartBuilder.new
2560
- builder.type(type) if type
2007
+ builder.type = type if type
2561
2008
  yield builder
2562
2009
  options = builder.options.merge(options)
2563
2010
  end
@@ -2595,16 +2042,14 @@ module Xlsxrb
2595
2042
  @current_hyperlinks << link
2596
2043
  end
2597
2044
 
2598
- # Sets the auto-filter range on the active sheet.
2045
+ # Returns the auto-filter range on the active sheet, or nil if none.
2599
2046
  #
2600
- # @param range [String, nil] Cell range (e.g. "A1:E100").
2601
- # @return [void]
2047
+ # @return [String, nil]
2602
2048
  # @api public
2603
- #: (String? range) -> void
2604
- def auto_filter(range)
2605
- sheet if @current_sheet.nil?
2606
- @current_auto_filter = range
2607
- nil
2049
+ #: () -> String?
2050
+ def auto_filter
2051
+ ensure_sheet_started!
2052
+ @current_auto_filter
2608
2053
  end
2609
2054
 
2610
2055
  # Sets the auto-filter range for the current worksheet.
@@ -2614,8 +2059,8 @@ module Xlsxrb
2614
2059
  # @api public
2615
2060
  #: (String? range) -> String?
2616
2061
  def auto_filter=(range)
2617
- auto_filter(range)
2618
- range
2062
+ ensure_sheet_started!
2063
+ @current_auto_filter = range&.to_s
2619
2064
  end
2620
2065
 
2621
2066
  # Sets filter criteria on a column in the auto-filter.
@@ -2630,7 +2075,7 @@ module Xlsxrb
2630
2075
  # @param filter [Hash] Filter definition.
2631
2076
  # @return [void]
2632
2077
  # @api public
2633
- #: (Integer | String | Symbol col_id, Hash[untyped, untyped] filter) -> void
2078
+ #: (Integer | String | Symbol col_id, (Hash[untyped, untyped] | Array[untyped]) filter) -> void
2634
2079
  def filter_column(col_id, filter)
2635
2080
  sheet if @current_sheet.nil?
2636
2081
  col_id = Elements::Cell._column_index(col_id) if col_id.is_a?(String) || col_id.is_a?(Symbol)
@@ -2638,33 +2083,38 @@ module Xlsxrb
2638
2083
  nil
2639
2084
  end
2640
2085
 
2641
- # Configures column sort state on the active sheet.
2086
+ # Configures or queries column sort state on the active sheet.
2642
2087
  #
2643
- # @param ref [String] The sorted range.
2644
- # @param sort_conditions [Array<Hash>] Sort conditions.
2088
+ # When called with no arguments, returns the {Elements::SortState} value object.
2089
+ # When called with arguments, updates sort state and returns nil.
2090
+ #
2091
+ # @param ref [String, nil] The sorted range.
2092
+ # @param sort_conditions [Array<Hash>, nil] Sort conditions.
2093
+ # @param case_sensitive [Boolean] Whether sorting is case sensitive.
2094
+ # @param sort_method [String, nil] Sort method.
2645
2095
  # @param opts [Hash] Additional options.
2646
- # @return [Elements::SortState, Hash<Symbol, untyped>, nil, void]
2096
+ # @return [Elements::SortState, nil, void]
2647
2097
  # @api public
2648
- #: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> (untyped | void)
2649
- def sort_state(ref = nil, sort_conditions = nil, **opts)
2098
+ #: () -> Elements::SortState?
2099
+ #: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, ?case_sensitive: bool, ?sort_method: String?, **untyped opts) -> void
2100
+ def sort_state(ref = nil, sort_conditions = nil, case_sensitive: false, sort_method: nil, **opts)
2650
2101
  sheet if @current_sheet.nil?
2651
- if ref.nil? && sort_conditions.nil? && opts.empty?
2652
- return nil unless @current_sort_state
2653
- return Elements::SortState.new(**@current_sort_state) if defined?(Elements::SortState)
2654
-
2655
- return @current_sort_state
2102
+ if ref.nil? && sort_conditions.nil?
2103
+ return @current_sort_state ? Elements::SortState.new(**@current_sort_state) : nil
2656
2104
  end
2657
2105
 
2658
- @current_sort_state = { ref: ref, sort_conditions: sort_conditions }.merge(opts)
2106
+ entry = { ref: ref, sort_conditions: sort_conditions, case_sensitive: case_sensitive }
2107
+ entry[:sort_method] = sort_method if sort_method
2108
+ @current_sort_state = entry.merge(opts)
2659
2109
  nil
2660
2110
  end
2661
2111
 
2662
- # Sets column sort state for the sheet.
2112
+ # Sets column sort state on the active sheet.
2663
2113
  #
2664
2114
  # @param opts [Elements::SortState, Hash, nil] Sort state options.
2665
2115
  # @return [void]
2666
2116
  # @api public
2667
- #: (untyped opts) -> void
2117
+ #: (Elements::SortState | Hash[Symbol, untyped] | nil opts) -> void
2668
2118
  def sort_state=(opts)
2669
2119
  sheet if @current_sheet.nil?
2670
2120
  @current_sort_state = opts&.respond_to?(:to_h) ? opts.to_h : opts
@@ -2685,13 +2135,6 @@ module Xlsxrb
2685
2135
  @current_data_validations.concat(normalized_list)
2686
2136
  end
2687
2137
 
2688
- # @deprecated Use {#data_validation} instead.
2689
- #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
2690
- def validate_data(...)
2691
- warn "[DEPRECATION] `validate_data` is deprecated; use `data_validation` instead.", uplevel: 1
2692
- data_validation(...)
2693
- end
2694
-
2695
2138
  # Adds a conditional formatting rule.
2696
2139
  # Supports block configuration via {ConditionalFormatBuilder} and coordinate targeting (:columns, :rows).
2697
2140
  #
@@ -2745,29 +2188,24 @@ module Xlsxrb
2745
2188
  # @param source_ref [String] Source data range.
2746
2189
  # @param row_fields [Array<Integer>] 0-based field indices for rows.
2747
2190
  # @param data_fields [Array<Hash>] Data fields.
2748
- # @param column_fields [Array<Integer>] 0-based field indices for columns.
2749
- # @param col_fields [Array<Integer>] Deprecated alias for column_fields.
2750
- # @param ref [String] Top-left destination cell (default: "E1").
2751
- # @param dest_ref [String] Deprecated alias for ref.
2191
+ # @param column_fields [Array<Integer>, nil] 0-based field indices for columns.
2192
+ # @param ref [String, nil] Top-left destination cell (default: "E1").
2752
2193
  # @param name [String, nil] Pivot table name.
2753
2194
  # @param field_names [Array<String>, nil] Override field names.
2754
- # @param items [Array, nil] Items configuration.
2195
+ # @param items [Hash{Integer => Array}, nil] Items of each field, by 0-based field index.
2755
2196
  # @param opts [Hash] Additional options.
2756
2197
  # @return [void]
2757
2198
  # @api public
2758
- #: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?col_fields: untyped, ?ref: untyped, ?dest_ref: untyped, ?name: untyped, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
2759
- def pivot_table(source_ref, row_fields:, data_fields:, column_fields: nil, col_fields: nil, ref: nil, dest_ref: nil, name: nil, field_names: nil, items: nil, **opts)
2199
+ #: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?ref: untyped, ?name: untyped, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
2200
+ def pivot_table(source_ref, row_fields:, data_fields:, column_fields: nil, ref: nil, name: nil, field_names: nil, items: nil, **opts)
2760
2201
  sheet if @current_sheet.nil?
2761
- warn "[DEPRECATION] `col_fields:` is deprecated; use `column_fields:` instead.", uplevel: 1 if col_fields && column_fields.nil?
2762
- warn "[DEPRECATION] `dest_ref:` is deprecated; use `ref:` instead.", uplevel: 1 if dest_ref && ref.nil?
2763
- c_fields = column_fields || col_fields || []
2764
- target_ref = ref || dest_ref || "E1"
2202
+ c_fields = column_fields || []
2203
+ target_ref = ref || "E1"
2765
2204
  @current_pivot_tables ||= []
2766
2205
  entry = {
2767
2206
  source_ref: source_ref, row_fields: row_fields,
2768
2207
  data_fields: data_fields, column_fields: c_fields,
2769
- col_fields: c_fields, ref: target_ref,
2770
- dest_ref: target_ref, name: name,
2208
+ ref: target_ref, destination: target_ref, name: name,
2771
2209
  field_names: field_names, items: items
2772
2210
  }.merge(opts)
2773
2211
  @current_pivot_tables << entry
@@ -2778,13 +2216,14 @@ module Xlsxrb
2778
2216
  # @param cell [String, Integer] Cell coordinate (e.g. "A1").
2779
2217
  # @param text [String] Comment text.
2780
2218
  # @param author [String] Author name.
2219
+ # @param visible [Boolean] Whether the comment is always shown instead of on hover.
2781
2220
  # @return [void]
2782
2221
  # @api public
2783
- #: (String | Integer cell, String text, ?author: ::String) -> void
2784
- def comment(cell, text, author: "Author")
2222
+ #: (String | Integer cell, String text, ?author: ::String, ?visible: bool) -> void
2223
+ def comment(cell, text, author: "Author", visible: false)
2785
2224
  sheet if @current_sheet.nil?
2786
2225
  ref_str = cell.to_s
2787
- @current_comments << { ref: ref_str, text: text, author: author }
2226
+ @current_comments << { ref: ref_str, text: text, author: author, visible: visible }
2788
2227
  nil
2789
2228
  end
2790
2229
 
@@ -2793,7 +2232,7 @@ module Xlsxrb
2793
2232
  # @param cell [String, Integer] Cell coordinate (e.g. "A1").
2794
2233
  # @param text [String] Comment text.
2795
2234
  # @param author [String] Author name.
2796
- # @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
2235
+ # @param visible [Boolean] Whether the comment is always shown instead of on hover. # @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
2797
2236
  # @param id [String, nil] Optional GUID for this comment.
2798
2237
  # @param parent_id [String, nil] Optional parent comment GUID for replies.
2799
2238
  # @param done [Boolean, nil] Optional resolved flag.
@@ -2810,16 +2249,17 @@ module Xlsxrb
2810
2249
  text: text,
2811
2250
  author: author,
2812
2251
  timestamp: timestamp,
2252
+ created_at: timestamp,
2813
2253
  id: id,
2814
2254
  parent_id: parent_id,
2815
2255
  done: done ? true : false,
2256
+ resolved: done ? true : false,
2816
2257
  user_id: user_id,
2258
+ author_id: user_id,
2817
2259
  provider_id: provider_id
2818
2260
  }.compact
2819
2261
  nil
2820
2262
  end
2821
- # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
2822
- alias add_threaded_comment threaded_comment
2823
2263
 
2824
2264
  # Adds a sparkline group.
2825
2265
  #
@@ -2837,86 +2277,46 @@ module Xlsxrb
2837
2277
  @current_sparkline_groups << group
2838
2278
  end
2839
2279
 
2840
- # Adds a single sparkline to the sheet.
2841
- #
2842
- # @example Add a line sparkline
2843
- # writer.add_sparkline(location: "F1", range: "A1:E1")
2844
- #
2845
- # @example Add a column sparkline with high/low markers
2846
- # writer.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
2847
- #
2848
- # @example Add a win/loss sparkline
2849
- # writer.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
2850
- #
2851
- # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
2852
- # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
2853
- # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
2854
- # @param opts [Hash] Additional sparkline options.
2855
- # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
2856
- # @return [void]
2857
- # @api public
2858
- #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
2859
- def add_sparkline(location: nil, range: nil, type: nil, **opts)
2860
- warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
2861
- loc = location || opts.delete(:location_ref)
2862
- rng = range || opts.delete(:data_ref) || opts.delete(:data)
2863
- raise ArgumentError, "Missing required location: parameter for sparkline" unless loc
2864
- raise ArgumentError, "Missing required range: parameter for sparkline" unless rng
2865
-
2866
- mapped_type = case type&.to_s
2867
- when "win_loss" then "stacked"
2868
- when nil, "" then nil
2869
- else type.to_s
2870
- end
2871
- sparkline_group(sparklines: [{ data_ref: rng.to_s, location_ref: loc.to_s }], type: mapped_type, **opts)
2872
- end
2873
-
2874
2280
  # Merges a range of cells into a single cell.
2875
2281
  #
2876
2282
  # @example
2877
2283
  # sheet.merge("A1:C1")
2878
2284
  #
2879
- # @deprecated Passing coordinate keyword arguments (row:, col_start:, col_end:, row_start:, row_end:) is deprecated and will be removed in 0.2.0. Use a range string (e.g. merge("A1:C1")) instead.
2880
- # @param range [String, Hash, nil] Cell range (e.g. "A1:B2") or hash of coordinates.
2881
- # @param row [Integer, nil] Single row index.
2882
- # @param col_start [Integer, String, nil] Starting column.
2883
- # @param col_end [Integer, String, nil] Ending column.
2884
- # @param row_start [Integer, nil] Starting row index.
2885
- # @param row_end [Integer, nil] Ending row index.
2285
+ # @param range [String] Cell range (e.g. "A1:B2").
2886
2286
  # @return [void]
2887
2287
  # @api public
2888
- #: (?(String | Hash[Symbol, Integer | String])? range, ?row: Integer?, ?col_start: (Integer | String)?, ?col_end: (Integer | String)?, ?row_start: Integer?, ?row_end: Integer?) -> void
2889
- def merge(range = nil, row: nil, col_start: nil, col_end: nil, row_start: nil, row_end: nil)
2288
+ #: (String range) -> void
2289
+ def merge(range)
2890
2290
  sheet if @current_sheet.nil?
2891
- canonical = DslHelpers.normalize_merge_range(
2892
- range,
2893
- row: row, col_start: col_start, col_end: col_end,
2894
- row_start: row_start, row_end: row_end,
2895
- strict_excel_mode: @strict_excel_mode
2896
- )
2291
+ canonical = DslHelpers.normalize_merge_range(range, strict_excel_mode: @strict_excel_mode)
2897
2292
  @current_merge_cells << canonical unless @current_merge_cells.include?(canonical)
2898
2293
  end
2899
2294
 
2900
- # Freezes window panes at the given row and column, or queries freeze pane settings.
2295
+ # Configures or queries freeze panes (<pane state="frozen">).
2296
+ #
2297
+ # When called with no arguments, returns the {Elements::FreezePane} value object or nil.
2298
+ # When called with arguments, configures the freeze pane and returns nil.
2901
2299
  #
2902
2300
  # @param row [Integer, nil] Number of rows to freeze.
2903
2301
  # @param column [Integer, String, nil] Number of columns to freeze.
2904
- # @param col [Integer, String, nil] Deprecated alias for column.
2905
- # @return [Elements::FreezePane, Hash<Symbol, untyped>, nil, void]
2302
+ # @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
2303
+ # @param active_pane [String, Symbol, nil] Active pane identifier.
2304
+ # @return [Elements::FreezePane, nil, void]
2906
2305
  # @api public
2907
- #: (?row: Integer | nil, ?column: (Integer | String)?, ?col: (Integer | String)?) -> (untyped | void)
2908
- def freeze_pane(row: nil, column: nil, col: nil)
2306
+ #: () -> Elements::FreezePane?
2307
+ #: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
2308
+ def freeze_pane(row: nil, column: nil, top_left_cell: nil, active_pane: nil)
2909
2309
  sheet if @current_sheet.nil?
2910
- if row.nil? && column.nil? && col.nil?
2911
- return nil unless @current_freeze_pane
2912
- return Elements::FreezePane.new(**@current_freeze_pane) if defined?(Elements::FreezePane)
2913
-
2914
- return @current_freeze_pane
2310
+ warn_late_sheet_setting("freeze_pane") unless row.nil? && column.nil? && top_left_cell.nil? && active_pane.nil?
2311
+ if row.nil? && column.nil? && top_left_cell.nil? && active_pane.nil?
2312
+ return @current_freeze_pane ? Elements::FreezePane.new(**@current_freeze_pane) : nil
2915
2313
  end
2916
2314
 
2917
- warn "[DEPRECATION] `col:` is deprecated; use `column:` instead.", uplevel: 1 if col && column.nil?
2918
- col_val = Elements::Cell._column_index(column || col || 0)
2919
- @current_freeze_pane = { row: row || 0, col: col_val, column: col_val }
2315
+ col_val = column ? Elements::Cell._column_index(column) : 0
2316
+ entry = { row: row || 0, column: col_val }
2317
+ entry[:top_left_cell] = top_left_cell if top_left_cell
2318
+ entry[:active_pane] = active_pane.to_s if active_pane
2319
+ @current_freeze_pane = entry
2920
2320
  nil
2921
2321
  end
2922
2322
 
@@ -2925,42 +2325,47 @@ module Xlsxrb
2925
2325
  # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
2926
2326
  # @return [void]
2927
2327
  # @api public
2928
- #: (untyped opts) -> void
2328
+ #: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
2929
2329
  def freeze_pane=(opts)
2930
2330
  sheet if @current_sheet.nil?
2331
+ warn_late_sheet_setting("freeze_pane=")
2931
2332
  if opts.nil?
2932
2333
  @current_freeze_pane = nil
2933
2334
  else
2934
2335
  h = opts.respond_to?(:to_h) ? opts.to_h : opts
2935
2336
  c = h[:column] || h[:col]
2936
2337
  c = Elements::Cell._column_index(c) if c
2937
- @current_freeze_pane = { row: h[:row] || 0, col: c || 0, column: c || 0 }
2338
+ entry = { row: h[:row] || 0, column: c || 0 }
2339
+ entry[:top_left_cell] = h[:top_left_cell] if h[:top_left_cell]
2340
+ entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
2341
+ @current_freeze_pane = entry
2938
2342
  end
2939
2343
  nil
2940
2344
  end
2941
2345
 
2942
- # Splits window panes without freezing or queries split pane settings.
2346
+ # Splits window panes without freezing or queries split pane settings (<pane>).
2347
+ #
2348
+ # When called with no arguments, returns the {Elements::SplitPane} value object or nil.
2349
+ # When called with arguments, configures the split pane and returns nil.
2943
2350
  #
2944
2351
  # @param x_split [Integer, nil] Horizontal split in points.
2945
2352
  # @param y_split [Integer, nil] Vertical split in points.
2946
2353
  # @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
2947
2354
  # @param active_pane [String, Symbol, nil] Active pane identifier.
2948
2355
  # @param state [String, Symbol, nil] Split state.
2949
- # @return [Elements::SplitPane, Hash<Symbol, untyped>, nil, void]
2356
+ # @return [Elements::SplitPane, nil, void]
2950
2357
  # @api public
2951
- #: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?, ?state: (String | Symbol)?) -> (untyped | void)
2952
- def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil, state: nil)
2358
+ #: () -> Elements::SplitPane?
2359
+ #: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
2360
+ def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil)
2953
2361
  sheet if @current_sheet.nil?
2954
- if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil? && state.nil?
2955
- return nil unless @current_split_pane
2956
- return Elements::SplitPane.new(**@current_split_pane) if defined?(Elements::SplitPane)
2957
-
2958
- return @current_split_pane
2362
+ warn_late_sheet_setting("split_pane") unless x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil?
2363
+ if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil?
2364
+ return @current_split_pane ? Elements::SplitPane.new(**@current_split_pane) : nil
2959
2365
  end
2960
2366
 
2961
2367
  entry = { x_split: x_split || 0, y_split: y_split || 0, top_left_cell: top_left_cell }
2962
2368
  entry[:active_pane] = active_pane.to_s if active_pane
2963
- entry[:state] = state.to_s if state
2964
2369
  @current_split_pane = entry
2965
2370
  nil
2966
2371
  end
@@ -2970,41 +2375,41 @@ module Xlsxrb
2970
2375
  # @param opts [Elements::SplitPane, Hash, nil] Split pane options.
2971
2376
  # @return [void]
2972
2377
  # @api public
2973
- #: (untyped opts) -> void
2378
+ #: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
2974
2379
  def split_pane=(opts)
2975
2380
  sheet if @current_sheet.nil?
2381
+ warn_late_sheet_setting("split_pane=")
2976
2382
  if opts.nil?
2977
2383
  @current_split_pane = nil
2978
2384
  else
2979
2385
  h = opts.respond_to?(:to_h) ? opts.to_h : opts
2980
2386
  entry = { x_split: h[:x_split] || 0, y_split: h[:y_split] || 0, top_left_cell: h[:top_left_cell] }
2981
2387
  entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
2982
- entry[:state] = h[:state].to_s if h[:state]
2983
2388
  @current_split_pane = entry
2984
2389
  end
2985
2390
  nil
2986
2391
  end
2987
2392
 
2988
- # Sets or queries the active cell selection on the current sheet.
2393
+ # Sets or queries the active cell selection on the current sheet (<selection>).
2394
+ #
2395
+ # When called with no arguments, returns the selection ({Elements::Selection}, Array, or nil).
2396
+ # When called with arguments, updates the selection and returns nil.
2989
2397
  #
2990
2398
  # @param active_cell [String, nil] Active cell reference (e.g. "A1") or range (e.g. "A1:D10").
2991
2399
  # @param sqref [String, nil] Selection range.
2992
2400
  # @param pane [String, Symbol, nil] Target pane.
2993
- # @return [Elements::Selection, Array<Elements::Selection>, Hash<Symbol, untyped>, nil, void]
2401
+ # @return [Elements::Selection, Array<Elements::Selection>, nil, void]
2994
2402
  # @api public
2995
- #: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> (untyped | void)
2403
+ #: () -> (Elements::Selection | Array[Elements::Selection])?
2404
+ #: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
2996
2405
  def selection(active_cell = nil, sqref: nil, pane: nil)
2997
2406
  sheet if @current_sheet.nil?
2407
+ warn_late_sheet_setting("selection") unless active_cell.nil? && sqref.nil? && pane.nil?
2998
2408
  if active_cell.nil? && sqref.nil? && pane.nil?
2999
2409
  return nil if @current_selection.nil?
2410
+ return @current_selection.map { |s| Elements::Selection.new(**s) } if @current_selection.is_a?(Array)
3000
2411
 
3001
- if defined?(Elements::Selection)
3002
- return @current_selection.map { |s| Elements::Selection.new(**s) } if @current_selection.is_a?(Array)
3003
-
3004
- return Elements::Selection.new(**@current_selection)
3005
- end
3006
-
3007
- return @current_selection
2412
+ return Elements::Selection.new(**@current_selection)
3008
2413
  end
3009
2414
 
3010
2415
  if sqref.nil? && active_cell.is_a?(String) && active_cell.include?(":")
@@ -3013,8 +2418,9 @@ module Xlsxrb
3013
2418
  else
3014
2419
  sqref ||= active_cell
3015
2420
  end
3016
- @current_selection = { active_cell: active_cell, sqref: sqref }
3017
- @current_selection[:pane] = pane if pane
2421
+ sel = { active_cell: active_cell, sqref: sqref }
2422
+ sel[:pane] = pane if pane
2423
+ @current_selection = sel
3018
2424
  nil
3019
2425
  end
3020
2426
 
@@ -3023,9 +2429,10 @@ module Xlsxrb
3023
2429
  # @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
3024
2430
  # @return [void]
3025
2431
  # @api public
3026
- #: (untyped opts) -> void
2432
+ #: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
3027
2433
  def selection=(opts)
3028
2434
  sheet if @current_sheet.nil?
2435
+ warn_late_sheet_setting("selection=")
3029
2436
  @current_selection = if opts.nil?
3030
2437
  nil
3031
2438
  elsif opts.is_a?(Array)
@@ -3036,16 +2443,9 @@ module Xlsxrb
3036
2443
  nil
3037
2444
  end
3038
2445
 
3039
- # @deprecated Use {#selection} instead.
3040
- #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
3041
- def select_cell(...)
3042
- warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
3043
- selection(...)
3044
- end
3045
-
3046
- # Configures page margins for printing (<pageMargins>).
2446
+ # Configures or queries page margins in inches for printing (<pageMargins>).
3047
2447
  #
3048
- # When called with no arguments, returns the page margins value object or hash.
2448
+ # When called with no arguments, returns the {Elements::PageMargins} value object or nil.
3049
2449
  # When called with arguments, configures page margins and returns nil.
3050
2450
  #
3051
2451
  # @param left [Float, nil] Left margin.
@@ -3054,16 +2454,14 @@ module Xlsxrb
3054
2454
  # @param bottom [Float, nil] Bottom margin.
3055
2455
  # @param header [Float, nil] Header margin.
3056
2456
  # @param footer [Float, nil] Footer margin.
3057
- # @return [Elements::PageMargins, Hash<Symbol, untyped>, nil, void]
2457
+ # @return [Elements::PageMargins, nil, void]
3058
2458
  # @api public
3059
- #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> (untyped | void)
2459
+ #: () -> Elements::PageMargins?
2460
+ #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> void
3060
2461
  def page_margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil)
3061
2462
  sheet if @current_sheet.nil?
3062
2463
  if left.nil? && right.nil? && top.nil? && bottom.nil? && header.nil? && footer.nil?
3063
- return nil unless @current_page_margins
3064
- return Elements::PageMargins.new(**@current_page_margins) if defined?(Elements::PageMargins)
3065
-
3066
- return @current_page_margins
2464
+ return @current_page_margins ? Elements::PageMargins.new(**@current_page_margins) : nil
3067
2465
  end
3068
2466
 
3069
2467
  @current_page_margins = DslHelpers.normalize_page_margins(
@@ -3077,7 +2475,7 @@ module Xlsxrb
3077
2475
  # @param opts [Hash, Elements::PageMargins, nil]
3078
2476
  # @return [void]
3079
2477
  # @api public
3080
- #: (untyped opts) -> void
2478
+ #: (Hash[Symbol, untyped] | Elements::PageMargins | nil opts) -> void
3081
2479
  def page_margins=(opts)
3082
2480
  sheet if @current_sheet.nil?
3083
2481
  if opts.nil?
@@ -3091,18 +2489,18 @@ module Xlsxrb
3091
2489
 
3092
2490
  # Configures or queries page setup configuration (<pageSetup>).
3093
2491
  #
3094
- # When called with no arguments, returns the page setup value object or hash.
2492
+ # When called with no arguments, returns the {Elements::PageSetup} value object.
3095
2493
  # When called with keyword arguments, updates page setup and returns nil.
3096
2494
  #
3097
2495
  # @param opts [Hash] Page setup options (e.g. orientation: :landscape).
3098
- # @return [Elements::PageSetup, Hash<Symbol, untyped>, void]
2496
+ # @return [Elements::PageSetup, void]
3099
2497
  # @api public
3100
- #: (**untyped opts) -> (untyped | void)
2498
+ #: () -> Elements::PageSetup
2499
+ #: (**untyped opts) -> void
3101
2500
  def page_setup(**opts)
3102
2501
  sheet if @current_sheet.nil?
3103
- if opts.empty?
3104
- return defined?(Elements::PageSetup) ? Elements::PageSetup.new(**@current_page_setup) : @current_page_setup
3105
- end
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)
2503
+ return Elements::PageSetup.new(**@current_page_setup) if opts.empty?
3106
2504
 
3107
2505
  @current_page_setup.merge!(opts)
3108
2506
  @current_sheet_properties[:fit_to_page] = true if (opts.key?(:fit_to_width) || opts.key?(:fit_to_height)) && !@current_sheet_properties.key?(:fit_to_page)
@@ -3114,7 +2512,7 @@ module Xlsxrb
3114
2512
  # @param opts [Hash, Elements::PageSetup]
3115
2513
  # @return [void]
3116
2514
  # @api public
3117
- #: (untyped opts) -> void
2515
+ #: (Hash[Symbol, untyped] | Elements::PageSetup opts) -> void
3118
2516
  def page_setup=(opts)
3119
2517
  sheet if @current_sheet.nil?
3120
2518
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
@@ -3124,18 +2522,17 @@ module Xlsxrb
3124
2522
 
3125
2523
  # Configures or queries headers and footers for printing (<headerFooter>).
3126
2524
  #
3127
- # When called with no arguments, returns the header/footer value object or hash.
2525
+ # When called with no arguments, returns the {Elements::HeaderFooter} value object.
3128
2526
  # When called with keyword arguments, updates headers and footers and returns nil.
3129
2527
  #
3130
2528
  # @param opts [Hash] Header/footer options.
3131
- # @return [Elements::HeaderFooter, Hash<Symbol, untyped>, void]
2529
+ # @return [Elements::HeaderFooter, void]
3132
2530
  # @api public
3133
- #: (**untyped opts) -> (untyped | void)
2531
+ #: () -> Elements::HeaderFooter
2532
+ #: (**untyped opts) -> void
3134
2533
  def header_footer(**opts)
3135
2534
  sheet if @current_sheet.nil?
3136
- if opts.empty?
3137
- return defined?(Elements::HeaderFooter) ? Elements::HeaderFooter.new(**@current_header_footer) : @current_header_footer
3138
- end
2535
+ return Elements::HeaderFooter.new(**@current_header_footer) if opts.empty?
3139
2536
 
3140
2537
  @current_header_footer.merge!(opts)
3141
2538
  nil
@@ -3146,7 +2543,7 @@ module Xlsxrb
3146
2543
  # @param opts [Hash, Elements::HeaderFooter]
3147
2544
  # @return [void]
3148
2545
  # @api public
3149
- #: (untyped opts) -> void
2546
+ #: (Hash[Symbol, untyped] | Elements::HeaderFooter opts) -> void
3150
2547
  def header_footer=(opts)
3151
2548
  sheet if @current_sheet.nil?
3152
2549
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
@@ -3157,23 +2554,17 @@ module Xlsxrb
3157
2554
  # Configures or queries print options (<printOptions>).
3158
2555
  #
3159
2556
  # When called with no arguments, returns the {Elements::PrintOptions} value object.
3160
- # When called with arguments or keyword options, configures print options and returns nil.
2557
+ # When called with keyword options, configures print options and returns nil.
3161
2558
  #
3162
- # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Option name or hash/record of options.
3163
- # @param value [Object, nil] Option value.
3164
2559
  # @param opts [Hash] Additional print options.
3165
2560
  # @return [Elements::PrintOptions, void]
3166
2561
  # @api public
3167
- #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::PrintOptions | void)
3168
- def print_options(name = nil, value = nil, **opts)
2562
+ #: () -> Elements::PrintOptions
2563
+ #: (**untyped opts) -> void
2564
+ def print_options(**opts)
3169
2565
  sheet if @current_sheet.nil?
3170
- return Elements::PrintOptions.new(**@current_print_options) if name.nil? && value.nil? && opts.empty?
2566
+ return Elements::PrintOptions.new(**@current_print_options) if opts.empty?
3171
2567
 
3172
- if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3173
- opts = name.to_h.merge(opts)
3174
- name = nil
3175
- end
3176
- @current_print_options[name.to_sym] = value if name && !value.nil?
3177
2568
  opts.each { |k, v| @current_print_options[k.to_sym] = v }
3178
2569
  nil
3179
2570
  end
@@ -3191,22 +2582,20 @@ module Xlsxrb
3191
2582
  nil
3192
2583
  end
3193
2584
 
3194
- # Configures or queries sheet-level protection with optional password hashing (<sheetProtection>).
2585
+ # Sets or queries sheet-level protection with optional password hashing (<sheetProtection>).
3195
2586
  #
3196
- # When called with no arguments, returns the sheet protection value object or hash.
2587
+ # When called with no arguments, returns the {Elements::SheetProtection} value object or nil.
3197
2588
  # When called with keyword arguments, sets sheet protection and returns nil.
3198
2589
  #
3199
2590
  # @param opts [Hash] Protection options.
3200
- # @return [Elements::SheetProtection, Hash<Symbol, untyped>, nil, void]
2591
+ # @return [Elements::SheetProtection, nil, void]
3201
2592
  # @api public
3202
- #: (**untyped opts) -> (untyped | void)
2593
+ #: () -> Elements::SheetProtection?
2594
+ #: (**untyped opts) -> void
3203
2595
  def sheet_protection(**opts)
3204
2596
  sheet if @current_sheet.nil?
3205
2597
  if opts.empty?
3206
- return nil unless @current_sheet_protection
3207
- return Elements::SheetProtection.new(**@current_sheet_protection) if defined?(Elements::SheetProtection)
3208
-
3209
- @current_sheet_protection
2598
+ @current_sheet_protection ? Elements::SheetProtection.new(**@current_sheet_protection) : nil
3210
2599
  else
3211
2600
  @current_sheet_protection = DslHelpers.normalize_protection_options(opts)
3212
2601
  nil
@@ -3218,7 +2607,7 @@ module Xlsxrb
3218
2607
  # @param opts [Elements::SheetProtection, Hash, Boolean, nil]
3219
2608
  # @return [void]
3220
2609
  # @api public
3221
- #: (untyped opts) -> void
2610
+ #: (Elements::SheetProtection | Hash[Symbol, untyped] | bool | nil opts) -> void
3222
2611
  def sheet_protection=(opts)
3223
2612
  sheet if @current_sheet.nil?
3224
2613
  if opts.nil? || opts == false
@@ -3232,63 +2621,53 @@ module Xlsxrb
3232
2621
  nil
3233
2622
  end
3234
2623
 
3235
- # @deprecated Use {#sheet_protection} instead.
3236
- #: (**untyped opts) -> void
3237
- def protect_sheet(...)
3238
- warn "[DEPRECATION] `protect_sheet` is deprecated; use `sheet_protection` instead.", uplevel: 1
3239
- sheet_protection(...)
3240
- end
3241
-
3242
2624
  # Inserts an embedded image into the active sheet.
3243
2625
  #
3244
2626
  # @param file_data [String] Binary image data.
3245
2627
  # @param ext [String] File extension ("png", "jpeg", etc.).
3246
2628
  # @param from_column [Integer, nil] Top-left starting column.
3247
- # @param from_col [Integer, nil] Deprecated alias for from_column.
3248
2629
  # @param from_row [Integer] Top-left starting row.
3249
2630
  # @param to_column [Integer, nil] Bottom-right ending column.
3250
- # @param to_col [Integer, nil] Deprecated alias for to_column.
3251
2631
  # @param to_row [Integer] Bottom-right ending row.
3252
2632
  # @param opts [Hash] Additional options.
3253
2633
  # @return [void]
3254
2634
  # @api public
3255
- #: (String file_data, ?ext: ::String, ?from_column: ::Integer?, ?from_col: ::Integer?, ?from_row: ::Integer, ?to_column: ::Integer?, ?to_col: ::Integer?, ?to_row: ::Integer, **untyped opts) -> void
3256
- def image(file_data, ext: "png", from_column: nil, from_col: nil, from_row: 0, to_column: nil, to_col: nil, to_row: 10, **opts)
3257
- warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
3258
- warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
3259
- fc = from_column || from_col || 0
3260
- tc = to_column || to_col || 5
2635
+ #: (String file_data, ?ext: ::String, ?from_column: ::Integer?, ?from_row: ::Integer, ?to_column: ::Integer?, ?to_row: ::Integer, **untyped opts) -> void
2636
+ def image(file_data, ext: "png", from_column: nil, from_row: 0, to_column: nil, to_row: 10, **opts)
2637
+ fc = from_column || 0
2638
+ tc = to_column || 5
3261
2639
  sheet if @current_sheet.nil?
3262
- img = { file_data: file_data, ext: ext, from_column: fc, from_col: fc, from_row: from_row, to_column: tc, to_col: tc, to_row: to_row }
2640
+ img = { file_data: file_data, ext: ext, from_column: fc, from_row: from_row, to_column: tc, to_row: to_row }
3263
2641
  img.merge!(opts)
3264
2642
  @current_images << img
3265
2643
  end
3266
2644
 
3267
- # Configures the worksheet background image (<picture>).
3268
- #
3269
- # @example Set background image from binary data
3270
- # sheet.background_image(png_bytes, ext: "png")
2645
+ # Worksheet background image (<picture>).
3271
2646
  #
3272
- # @example Set background image from file path
3273
- # sheet.background_image("path/to/background.png")
3274
- #
3275
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
3276
- # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
3277
- # @param ext [String, nil] Image extension ("png", "jpeg", "jpg", "gif", etc.).
3278
- # @param opts [Hash] Additional image options.
3279
- # @return [Hash, nil]
2647
+ # @return [Elements::BackgroundImage, nil]
3280
2648
  # @api public
3281
- #: (?untyped file_data, ?ext: ::String?, **untyped opts) -> Hash[Symbol, untyped]?
3282
- def background_image(file_data = nil, ext: nil, **opts)
3283
- if file_data.nil? && ext.nil? && opts.empty?
3284
- return nil unless @current_background_image
2649
+ #: () -> Elements::BackgroundImage?
2650
+ def background_image
2651
+ sheet if @current_sheet.nil?
2652
+ return nil unless @current_background_image
3285
2653
 
3286
- return @current_background_image.is_a?(Elements::BackgroundImage) ? @current_background_image : Elements::BackgroundImage.new(**@current_background_image)
3287
- end
2654
+ @current_background_image.is_a?(Elements::BackgroundImage) ? @current_background_image : Elements::BackgroundImage.new(**@current_background_image)
2655
+ end
3288
2656
 
2657
+ # Sets the worksheet background image (<picture>).
2658
+ #
2659
+ # @param val [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
2660
+ # @return [untyped]
2661
+ # @api public
2662
+ #: (untyped val) -> untyped
2663
+ def background_image=(val)
3289
2664
  sheet if @current_sheet.nil?
2665
+ if val.nil?
2666
+ @current_background_image = nil
2667
+ return
2668
+ end
3290
2669
 
3291
- data = file_data
2670
+ data = val
3292
2671
  inferred_ext = nil
3293
2672
  if data.is_a?(String) && !data.include?("\x00") && File.file?(data)
3294
2673
  inferred_ext = File.extname(data).delete_prefix(".").downcase
@@ -3301,7 +2680,7 @@ module Xlsxrb
3301
2680
  data = data.data
3302
2681
  end
3303
2682
 
3304
- final_ext = (ext || inferred_ext || opts[:ext] || "png").to_s.delete_prefix(".").downcase
2683
+ final_ext = (inferred_ext || (val.is_a?(Hash) ? val[:ext] : nil) || "png").to_s.delete_prefix(".").downcase
3305
2684
  mime = case final_ext
3306
2685
  when "png" then "image/png"
3307
2686
  when "jpg", "jpeg" then "image/jpeg"
@@ -3312,75 +2691,49 @@ module Xlsxrb
3312
2691
  else "application/octet-stream"
3313
2692
  end
3314
2693
 
2694
+ opts = val.is_a?(Hash) ? val : {}
3315
2695
  @current_background_image = {
3316
2696
  data: data&.b,
3317
2697
  file_data: data&.b,
2698
+ extension: final_ext,
3318
2699
  ext: final_ext,
2700
+ path: "background.#{final_ext}",
3319
2701
  filename: "background.#{final_ext}",
3320
2702
  content_type: mime
3321
2703
  }.merge(opts).freeze
3322
- end
3323
- # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
3324
- alias background_picture background_image
3325
- # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
3326
- alias picture background_image
3327
-
3328
- #: (untyped val) -> untyped
3329
- def background_image=(val)
3330
- sheet if @current_sheet.nil?
3331
- if val.nil?
3332
- @current_background_image = nil
3333
- else
3334
- background_image(val)
3335
- end
3336
2704
  val
3337
2705
  end
3338
- # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
3339
- alias background_picture= background_image=
3340
- # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
3341
- alias picture= background_image=
3342
2706
 
3343
2707
  # Inserts a drawing shape.
3344
2708
  #
3345
2709
  # @param preset [String] Preset shape name.
3346
2710
  # @param text [String, nil] Label text.
3347
2711
  # @param from_column [Integer, nil] Top-left column.
3348
- # @param from_col [Integer, nil] Deprecated alias for from_column.
3349
2712
  # @param from_row [Integer] Top-left row.
3350
2713
  # @param to_column [Integer, nil] Bottom-right column.
3351
- # @param to_col [Integer, nil] Deprecated alias for to_column.
3352
2714
  # @param to_row [Integer] Bottom-right row.
3353
2715
  # @param opts [Hash] Additional options.
3354
2716
  # @return [void]
3355
2717
  # @api public
3356
2718
  #: (**untyped opts) -> void
3357
- def shape(preset: "rect", text: nil, from_column: nil, from_col: nil, from_row: 0, to_column: nil, to_col: nil, to_row: 5, **opts)
3358
- warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
3359
- warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
3360
- fc = from_column || from_col || 0
3361
- tc = to_column || to_col || 5
2719
+ def shape(preset: "rect", text: nil, from_column: nil, from_row: 0, to_column: nil, to_row: 5, **opts)
2720
+ fc = from_column || 0
2721
+ tc = to_column || 5
3362
2722
  sheet if @current_sheet.nil?
3363
- shape_data = { preset: preset, text: text, from_column: fc, from_col: fc, from_row: from_row, to_column: tc, to_col: tc, to_row: to_row }
2723
+ shape_data = { preset: preset, text: text, from_column: fc, from_row: from_row, to_column: tc, to_row: to_row }
3364
2724
  shape_data[:name] = opts.delete(:name) || "Shape #{@current_shapes.size + 1}"
3365
2725
  shape_data.merge!(opts)
3366
2726
  @current_shapes << shape_data
3367
2727
  end
3368
2728
 
3369
- # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
2729
+ # Gets the sheet visibility state (:visible, :hidden, or :very_hidden).
3370
2730
  #
3371
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
3372
- # @param new_state [Symbol, nil] The new state.
3373
2731
  # @return [Symbol]
3374
2732
  # @api public
3375
- #: (?Symbol? new_state) -> Symbol
3376
- def state(new_state = nil)
2733
+ #: () -> Symbol
2734
+ def state
3377
2735
  sheet if @current_sheet.nil?
3378
- if new_state
3379
- sheet_properties(:state, new_state)
3380
- @current_sheet_state
3381
- else
3382
- @current_sheet_state || :visible
3383
- end
2736
+ @current_sheet_state || :visible
3384
2737
  end
3385
2738
 
3386
2739
  # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
@@ -3391,30 +2744,18 @@ module Xlsxrb
3391
2744
  #: (Symbol | String new_state) -> Symbol
3392
2745
  def state=(new_state)
3393
2746
  sheet if @current_sheet.nil?
3394
- sheet_properties(:state, new_state)
2747
+ sheet_properties(state: new_state)
3395
2748
  @current_sheet_state
3396
2749
  end
3397
2750
 
3398
- # Gets or sets the tab color of the current worksheet.
2751
+ # Gets the tab color of the current worksheet.
3399
2752
  #
3400
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
3401
- # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
3402
- # @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5).
3403
2753
  # @return [String, Hash, nil]
3404
2754
  # @api public
3405
- #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
3406
- def tab_color(spec = OMITTED, **opts)
2755
+ #: () -> (String | Hash[Symbol, untyped] | nil)
2756
+ def tab_color
3407
2757
  sheet if @current_sheet.nil?
3408
- if spec.equal?(OMITTED) && opts.empty?
3409
- @current_sheet_properties[:tab_color]
3410
- else
3411
- color = if opts.empty?
3412
- spec
3413
- else
3414
- spec.is_a?(Hash) ? spec.merge(opts) : opts
3415
- end
3416
- @current_sheet_properties[:tab_color] = color
3417
- end
2758
+ @current_sheet_properties[:tab_color]
3418
2759
  end
3419
2760
 
3420
2761
  # Sets the tab color of the current worksheet.
@@ -3425,54 +2766,38 @@ module Xlsxrb
3425
2766
  #: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
3426
2767
  def tab_color=(spec)
3427
2768
  sheet if @current_sheet.nil?
2769
+ warn_late_sheet_setting("tab_color=")
3428
2770
  @current_sheet_properties[:tab_color] = spec
3429
2771
  end
3430
2772
 
3431
- # Sets a single sheet property.
3432
- #
3433
- # @param name [Symbol, String] Property name.
3434
- # @param value [Object] Property value.
3435
- # @return [void]
3436
- # @api public
3437
- #: (Symbol | String name, untyped value) -> void
3438
- def sheet_property(name, value)
3439
- sheet_properties(name, value)
3440
- end
3441
-
3442
2773
  # Configures or queries sheet properties (<sheetPr>).
3443
2774
  #
3444
2775
  # When called with no arguments, returns the {Elements::SheetProperties} value object.
3445
- # When called with arguments or keyword options, configures properties and returns nil.
2776
+ # When called with keyword options, configures properties and returns nil.
3446
2777
  #
3447
- # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
3448
- # @param value [Object, nil] Property value when name is provided.
3449
2778
  # @param opts [Hash] Additional sheet properties.
3450
2779
  # @return [Elements::SheetProperties, void]
3451
2780
  # @api public
3452
- #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetProperties | void)
3453
- def sheet_properties(name = nil, value = nil, **opts)
2781
+ #: () -> Elements::SheetProperties
2782
+ #: (**untyped opts) -> void
2783
+ def sheet_properties(**opts)
3454
2784
  sheet if @current_sheet.nil?
3455
- return Elements::SheetProperties.new(**@current_sheet_properties) if name.nil? && value.nil? && opts.empty?
2785
+ warn_late_sheet_setting("sheet_properties") unless opts.empty?
2786
+ return Elements::SheetProperties.new(**@current_sheet_properties) if opts.empty?
3456
2787
 
3457
- if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3458
- opts = name.to_h.merge(opts)
3459
- name = nil
3460
- end
3461
- if name && !value.nil?
3462
- sym = name.to_sym
2788
+ opts.each do |k, v|
2789
+ sym = k.to_sym
3463
2790
  if sym == :state
3464
- val = value.to_sym
2791
+ val = v.to_sym
3465
2792
  raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
3466
2793
 
3467
2794
  @current_sheet_state = val
3468
- return nil
3469
2795
  elsif sym == :hidden
3470
- @current_sheet_state = value ? :hidden : :visible
3471
- return nil
2796
+ @current_sheet_state = v ? :hidden : :visible
2797
+ else
2798
+ @current_sheet_properties[sym] = v
3472
2799
  end
3473
- @current_sheet_properties[name.to_sym] = value
3474
2800
  end
3475
- opts.each { |k, v| sheet_properties(k, v) }
3476
2801
  nil
3477
2802
  end
3478
2803
 
@@ -3484,32 +2809,28 @@ module Xlsxrb
3484
2809
  #: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
3485
2810
  def sheet_properties=(opts)
3486
2811
  sheet if @current_sheet.nil?
2812
+ warn_late_sheet_setting("sheet_properties=")
3487
2813
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3488
2814
  @current_sheet_properties = {}
3489
- h.each { |k, v| sheet_properties(k, v) }
2815
+ sheet_properties(**h)
3490
2816
  nil
3491
2817
  end
3492
2818
 
3493
2819
  # Configures or queries sheet view display properties (<sheetView>).
3494
2820
  #
3495
2821
  # When called with no arguments, returns the {Elements::SheetView} value object.
3496
- # When called with arguments or keyword options, configures view properties and returns nil.
2822
+ # When called with keyword options, configures view properties and returns nil.
3497
2823
  #
3498
- # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] View property name or hash/record of properties.
3499
- # @param value [Object, nil] View property value when name is provided.
3500
2824
  # @param opts [Hash] Additional view properties.
3501
2825
  # @return [Elements::SheetView, void]
3502
2826
  # @api public
3503
- #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetView | void)
3504
- def sheet_view(name = nil, value = nil, **opts)
2827
+ #: () -> Elements::SheetView
2828
+ #: (**untyped opts) -> void
2829
+ def sheet_view(**opts)
3505
2830
  sheet if @current_sheet.nil?
3506
- return Elements::SheetView.new(**@current_sheet_view) if name.nil? && value.nil? && opts.empty?
2831
+ warn_late_sheet_setting("sheet_view") unless opts.empty?
2832
+ return Elements::SheetView.new(**@current_sheet_view) if opts.empty?
3507
2833
 
3508
- if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3509
- opts = name.to_h.merge(opts)
3510
- name = nil
3511
- end
3512
- @current_sheet_view[name.to_sym] = value if name && !value.nil?
3513
2834
  opts.each { |k, v| @current_sheet_view[k.to_sym] = v }
3514
2835
  nil
3515
2836
  end
@@ -3522,6 +2843,7 @@ module Xlsxrb
3522
2843
  #: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
3523
2844
  def sheet_view=(opts)
3524
2845
  sheet if @current_sheet.nil?
2846
+ warn_late_sheet_setting("sheet_view=")
3525
2847
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3526
2848
  @current_sheet_view = h.transform_keys(&:to_sym)
3527
2849
  nil
@@ -3530,36 +2852,19 @@ module Xlsxrb
3530
2852
  # Configures or queries sheet format properties (<sheetFormatPr>).
3531
2853
  #
3532
2854
  # When called with no arguments, returns the {Elements::SheetFormat} value object.
3533
- # When called with arguments or keyword options, configures format properties and returns nil.
2855
+ # When called with keyword options, configures format properties and returns nil.
3534
2856
  #
3535
- # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
3536
- # @param value [Object, nil] Property value when name is provided.
3537
2857
  # @param opts [Hash] Keyword arguments for sheet format properties.
3538
2858
  # @return [Elements::SheetFormat, void]
3539
2859
  # @api public
3540
- #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
3541
- def sheet_format(name = nil, value = nil, **opts)
2860
+ #: () -> Elements::SheetFormat
2861
+ #: (**untyped opts) -> void
2862
+ def sheet_format(**opts)
3542
2863
  sheet if @current_sheet.nil?
3543
- return Elements::SheetFormat.new(**@current_sheet_format) if name.nil? && value.nil? && opts.empty?
2864
+ warn_late_sheet_setting("sheet_format") unless opts.empty?
2865
+ return Elements::SheetFormat.new(**@current_sheet_format) if opts.empty?
3544
2866
 
3545
- if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3546
- @current_sheet_format.merge!(name.to_h)
3547
- elsif name && value
3548
- @current_sheet_format[name.to_sym] = value
3549
- end
3550
- if opts.key?(:default_col_width) && !opts.key?(:default_column_width)
3551
- warn "[DEPRECATION] `default_col_width:` is deprecated; use `default_column_width:` instead.", uplevel: 1
3552
- opts[:default_column_width] = opts[:default_col_width]
3553
- end
3554
- if opts.key?(:base_col_width) && !opts.key?(:base_column_width)
3555
- warn "[DEPRECATION] `base_col_width:` is deprecated; use `base_column_width:` instead.", uplevel: 1
3556
- opts[:base_column_width] = opts[:base_col_width]
3557
- end
3558
- if opts.key?(:outline_level_col) && !opts.key?(:outline_level_column)
3559
- warn "[DEPRECATION] `outline_level_col:` is deprecated; use `outline_level_column:` instead.", uplevel: 1
3560
- opts[:outline_level_column] = opts[:outline_level_col]
3561
- end
3562
- @current_sheet_format.merge!(opts) unless opts.empty?
2867
+ opts.each { |k, v| @current_sheet_format[k.to_sym] = v }
3563
2868
  nil
3564
2869
  end
3565
2870
 
@@ -3571,9 +2876,9 @@ module Xlsxrb
3571
2876
  #: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
3572
2877
  def sheet_format=(opts)
3573
2878
  sheet if @current_sheet.nil?
2879
+ warn_late_sheet_setting("sheet_format=")
3574
2880
  h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3575
- @current_sheet_format = {}
3576
- sheet_format(h)
2881
+ @current_sheet_format = h.transform_keys(&:to_sym)
3577
2882
  nil
3578
2883
  end
3579
2884
 
@@ -3588,13 +2893,6 @@ module Xlsxrb
3588
2893
  @current_row_breaks << { id: row_index, max: 16_383, man: 1 }
3589
2894
  end
3590
2895
 
3591
- # @deprecated Use {#row_break} instead.
3592
- #: (Integer row_num) -> void
3593
- def page_break_row(row_num)
3594
- warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
3595
- row_break(row_num)
3596
- end
3597
-
3598
2896
  # Inserts a vertical page break after the given column.
3599
2897
  #
3600
2898
  # @param col [Integer, String, Symbol] 0-based column index or letter ("B", :B).
@@ -3607,13 +2905,6 @@ module Xlsxrb
3607
2905
  @current_col_breaks << { id: col_index, max: 1_048_575, man: 1 }
3608
2906
  end
3609
2907
 
3610
- # @deprecated Use {#column_break} instead.
3611
- #: (Integer | String | Symbol col_index) -> void
3612
- def page_break_col(col_index)
3613
- warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
3614
- column_break(col_index)
3615
- end
3616
-
3617
2908
  # Adds a protected range to the current sheet.
3618
2909
  #
3619
2910
  # @param name [String] Name of the protected range.
@@ -3630,8 +2921,6 @@ module Xlsxrb
3630
2921
  entry.merge!(opts) unless opts.empty?
3631
2922
  @current_protected_ranges << DslHelpers.normalize_protection_options(entry)
3632
2923
  end
3633
- # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
3634
- alias add_protected_range protected_range
3635
2924
 
3636
2925
  # Adds a cell watch to the current sheet.
3637
2926
  #
@@ -3643,8 +2932,6 @@ module Xlsxrb
3643
2932
  sheet if @current_sheet.nil?
3644
2933
  @current_cell_watches << ref.to_s
3645
2934
  end
3646
- # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
3647
- alias add_cell_watch cell_watch
3648
2935
 
3649
2936
  # Adds an ignored error entry to the current sheet.
3650
2937
  #
@@ -3658,66 +2945,26 @@ module Xlsxrb
3658
2945
  @current_ignored_errors << { sqref: sqref.to_s }.merge(opts)
3659
2946
  end
3660
2947
 
3661
- # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
3662
- #: (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
3663
- def ignore_error(sqref, **opts)
3664
- warn "[DEPRECATION] #ignore_error is deprecated; use #ignored_error instead.", uplevel: 1
3665
- ignored_error(sqref, **opts)
3666
- end
3667
-
3668
- # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
3669
- #: (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
3670
- def add_ignored_error(sqref, **opts)
3671
- warn "[DEPRECATION] #add_ignored_error is deprecated; use #ignored_error instead.", uplevel: 1
3672
- ignored_error(sqref, **opts)
3673
- end
3674
-
3675
2948
  # Returns the ignored error entries configured for the current sheet.
3676
2949
  #
3677
- # @return [Array<Hash[Symbol, untyped]>]
2950
+ # @return [Array<Elements::IgnoredError>]
3678
2951
  # @api public
3679
- #: () -> Array[Hash[Symbol, untyped]]
2952
+ #: () -> Array[Elements::IgnoredError]
3680
2953
  def ignored_errors
3681
2954
  @current_ignored_errors.map { |ie| ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie) }.freeze
3682
2955
  end
3683
2956
 
3684
- # Gets or sets phonetic (furigana) guide properties for the current sheet.
2957
+ # Phonetic (furigana) guide properties for the current sheet.
3685
2958
  #
3686
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
3687
- # @overload phonetic_properties()
3688
- # Returns the current phonetic properties.
3689
- # @return [Hash, nil]
3690
- # @overload phonetic_properties(spec = nil, font_id: nil, type: nil, alignment: nil)
3691
- # Sets phonetic properties for the current sheet.
3692
- # @param spec [Hash, Integer, nil]
3693
- # @param font_id [Integer, nil]
3694
- # @param type [Symbol, String, nil]
3695
- # @param alignment [Symbol, String, nil]
3696
- # @return [Hash, nil]
2959
+ # @return [Elements::PhoneticProperties, nil]
3697
2960
  # @api public
3698
- #: (?untyped spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> (Elements::PhoneticProperties | Hash[Symbol, untyped] | nil)
3699
- def phonetic_properties(spec = OMITTED, font_id: nil, type: nil, alignment: nil, **opts)
2961
+ #: () -> Elements::PhoneticProperties?
2962
+ def phonetic_properties
3700
2963
  sheet if @current_sheet.nil?
3701
- if spec.equal?(OMITTED) && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
3702
- return nil unless @current_phonetic_properties
2964
+ return nil unless @current_phonetic_properties
3703
2965
 
3704
- @current_phonetic_properties.is_a?(Elements::PhoneticProperties) ? @current_phonetic_properties : Elements::PhoneticProperties.new(**@current_phonetic_properties)
3705
- elsif !spec.equal?(OMITTED) && spec.nil? && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
3706
- @current_phonetic_properties = nil
3707
- else
3708
- props = if spec.is_a?(Hash)
3709
- spec.merge(opts)
3710
- elsif spec.is_a?(Integer)
3711
- { font_id: spec, type: type, alignment: alignment }.merge(opts)
3712
- else
3713
- { font_id: font_id, type: type, alignment: alignment }.merge(opts)
3714
- end
3715
- props.compact!
3716
- @current_phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
3717
- end
2966
+ @current_phonetic_properties.is_a?(Elements::PhoneticProperties) ? @current_phonetic_properties : Elements::PhoneticProperties.new(**@current_phonetic_properties)
3718
2967
  end
3719
- # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
3720
- alias phonetic_pr phonetic_properties
3721
2968
 
3722
2969
  # Sets phonetic (furigana) guide properties for the current sheet.
3723
2970
  #
@@ -3741,27 +2988,17 @@ module Xlsxrb
3741
2988
  end
3742
2989
  spec
3743
2990
  end
3744
- # @deprecated Use {#phonetic_properties=} instead. Will be removed in 0.2.0.
3745
- alias phonetic_pr= phonetic_properties=
3746
2991
 
3747
- # Sets or gets the internal code name of the current worksheet (or workbook if no sheet is open).
2992
+ # Gets the internal code name of the current worksheet (or workbook if no sheet is open).
3748
2993
  #
3749
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
3750
- # @param val [String, Symbol, nil] The code name.
3751
2994
  # @return [String, nil]
3752
2995
  # @api public
3753
- #: (?String | Symbol | nil val) -> String?
3754
- def code_name(val = OMITTED)
2996
+ #: () -> String?
2997
+ def code_name
3755
2998
  if @current_sheet.nil?
3756
- if val.equal?(OMITTED)
3757
- @workbook_properties[:code_name]
3758
- else
3759
- @workbook_properties[:code_name] = val&.to_s
3760
- end
3761
- elsif val.equal?(OMITTED)
3762
- @current_sheet_properties[:code_name]
2999
+ @workbook_properties[:code_name]
3763
3000
  else
3764
- @current_sheet_properties[:code_name] = val&.to_s
3001
+ @current_sheet_properties[:code_name]
3765
3002
  end
3766
3003
  end
3767
3004
 
@@ -3775,42 +3012,19 @@ module Xlsxrb
3775
3012
  if @current_sheet.nil?
3776
3013
  @workbook_properties[:code_name] = val&.to_s
3777
3014
  else
3015
+ warn_late_sheet_setting("code_name=")
3778
3016
  @current_sheet_properties[:code_name] = val&.to_s
3779
3017
  end
3780
3018
  end
3781
3019
 
3782
- # Configures whether page setup fits content to page width/height for the current sheet.
3783
- # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
3020
+ # Returns whether page setup fits content to page width/height for the current sheet.
3784
3021
  #
3785
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fit_to_page=} or {#page_setup} with :fit_to_width/:fit_to_height instead.
3786
- # @param enabled [Boolean, nil] Whether to fit to page.
3787
- # @param width [Integer, nil] Pages wide to fit to.
3788
- # @param height [Integer, nil] Pages tall to fit to.
3789
- # @return [Boolean, void]
3790
- # @api public
3791
- #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
3792
- def fit_to_page(enabled = OMITTED, width: nil, height: nil)
3793
- sheet if @current_sheet.nil?
3794
- if enabled.equal?(OMITTED) && width.nil? && height.nil?
3795
- return @current_sheet_properties[:fit_to_page] ? true : false
3796
- end
3797
-
3798
- @current_sheet_properties[:fit_to_page] = if enabled.equal?(OMITTED)
3799
- true
3800
- else
3801
- enabled ? true : false
3802
- end
3803
- page_setup(fit_to_width: width) if width
3804
- page_setup(fit_to_height: height) if height
3805
- end
3806
-
3807
- # @deprecated Use {#fit_to_page} instead. Will be removed in 0.2.0.
3808
3022
  # @return [Boolean]
3809
3023
  # @api public
3810
3024
  #: () -> bool
3811
3025
  def fit_to_page?
3812
- warn "[Xlsxrb DEPRECATION] fit_to_page? is deprecated; use fit_to_page instead.", uplevel: 1
3813
- fit_to_page
3026
+ sheet if @current_sheet.nil?
3027
+ @current_sheet_properties[:fit_to_page] ? true : false
3814
3028
  end
3815
3029
 
3816
3030
  # Sets whether page setup fits content to page width/height for the current sheet.
@@ -3821,40 +3035,24 @@ module Xlsxrb
3821
3035
  #: (bool? enabled) -> bool?
3822
3036
  def fit_to_page=(enabled)
3823
3037
  sheet if @current_sheet.nil?
3038
+ warn_late_sheet_setting("fit_to_page=")
3824
3039
  @current_sheet_properties[:fit_to_page] = enabled ? true : false
3825
3040
  end
3826
3041
 
3827
- # Configures worksheet calculation properties (<sheetCalcPr>) for the current sheet.
3042
+ # Worksheet calculation properties (<sheetCalcPr>) for the current sheet.
3828
3043
  #
3829
3044
  # @example Instruct Excel to recalculate formulas when loading sheet
3830
3045
  # w.sheet_calc_properties = { full_calc_on_load: true }
3831
3046
  #
3832
- # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
3833
- # @param spec [Hash, nil] Calculation properties hash.
3834
- # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
3835
- # @return [Hash, nil]
3047
+ # @return [Elements::SheetCalcProperties, nil]
3836
3048
  # @api public
3837
- #: (?untyped spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3838
- def sheet_calc_properties(spec = OMITTED, full_calc_on_load: nil, **opts)
3049
+ #: () -> Elements::SheetCalcProperties?
3050
+ def sheet_calc_properties
3839
3051
  sheet if @current_sheet.nil?
3840
- if spec.equal?(OMITTED) && full_calc_on_load.nil? && opts.empty?
3841
- calc = @current_sheet_calc_pr || (@current_sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
3842
- return nil unless calc
3843
-
3844
- return calc.is_a?(Elements::SheetCalcProperties) ? calc : Elements::SheetCalcProperties.new(**calc)
3845
- end
3846
-
3847
- warn "[DEPRECATION] Calling #sheet_calc_properties with arguments is deprecated and will be removed in 0.2.0. Use #sheet_calc_properties= instead.", uplevel: 1
3848
- if !spec.equal?(OMITTED) && spec.nil? && full_calc_on_load.nil? && opts.empty?
3849
- @current_sheet_properties.delete(:full_calc_on_load)
3850
- return @current_sheet_calc_pr = nil
3851
- end
3052
+ calc = @current_sheet_calc_pr || (@current_sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
3053
+ return nil unless calc
3852
3054
 
3853
- pr = spec.is_a?(Hash) ? spec.dup : {}
3854
- pr[:full_calc_on_load] = full_calc_on_load unless full_calc_on_load.nil?
3855
- pr.merge!(opts) unless opts.empty?
3856
- @current_sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
3857
- @current_sheet_calc_pr = pr
3055
+ calc.is_a?(Elements::SheetCalcProperties) ? calc : Elements::SheetCalcProperties.new(**calc)
3858
3056
  end
3859
3057
 
3860
3058
  # Sets worksheet calculation properties (<sheetCalcPr>) for the current sheet.
@@ -3876,34 +3074,6 @@ module Xlsxrb
3876
3074
  spec
3877
3075
  end
3878
3076
 
3879
- # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
3880
- #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3881
- def sheet_calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
3882
- warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
3883
- sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
3884
- end
3885
-
3886
- # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
3887
- #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3888
- def calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
3889
- warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
3890
- sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
3891
- end
3892
-
3893
- # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
3894
- #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
3895
- def sheet_calc_pr=(spec)
3896
- warn "[DEPRECATION] #sheet_calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
3897
- self.sheet_calc_properties = spec
3898
- end
3899
-
3900
- # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
3901
- #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
3902
- def calc_pr=(spec)
3903
- warn "[DEPRECATION] #calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
3904
- self.sheet_calc_properties = spec
3905
- end
3906
-
3907
3077
  # --- Workbook-Level Methods ---
3908
3078
 
3909
3079
  # Adds a defined name.
@@ -3913,32 +3083,17 @@ module Xlsxrb
3913
3083
  # @param sheet [String, nil] Reference sheet name.
3914
3084
  # @param scope [String, Symbol, nil] Local scope sheet name or :workbook.
3915
3085
  # @param hidden [Boolean] Whether the defined name is hidden.
3916
- # @param column [Integer, String, nil] Deprecated alias for columns.
3917
3086
  # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
3918
- # @param col [Integer, String, nil] Deprecated alias for column.
3919
- # @param row [Integer, Range, nil] Deprecated alias for rows.
3920
- # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
3087
+ # @param rows [Integer, Range, nil] Row or row range (0-based) for coordinate-based reference.
3921
3088
  # @param range [String, nil] Cell range reference.
3922
- # @param ref_sheet [String, nil] Deprecated alias for sheet.
3923
- # @param local [Boolean] Deprecated alias for scope.
3924
3089
  # @return [void]
3925
3090
  # @api public
3926
- #: (String name, ?untyped value, ?sheet: String?, ?scope: (String | Symbol)?, ?hidden: bool, ?column: untyped, ?columns: untyped, ?col: untyped, ?row: untyped, ?rows: untyped, ?range: untyped, ?ref_sheet: String?, ?local: bool) -> void
3927
- def defined_name(name, value = nil, sheet: nil, scope: nil, hidden: false, column: nil, columns: nil, col: nil, row: nil, rows: nil, range: nil, ref_sheet: nil, local: false)
3928
- warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
3929
- warn "[DEPRECATION] `ref_sheet:` is deprecated; use `sheet:` for reference sheet and `scope:` for scope instead.", uplevel: 1 if ref_sheet
3930
- warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
3931
- warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
3932
- warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
3933
- target_ref_sheet = ref_sheet || sheet
3934
- c_arg = column || columns || col
3935
- r_arg = row || rows
3936
- normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: target_ref_sheet, col: c_arg, rows: r_arg, range: range)
3091
+ #: (String name, ?untyped value, ?sheet: String?, ?scope: (String | Symbol)?, ?hidden: bool, ?columns: untyped, ?rows: untyped, ?range: untyped) -> void
3092
+ def defined_name(name, value = nil, sheet: nil, scope: nil, hidden: false, columns: nil, rows: nil, range: nil)
3093
+ normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: sheet, columns: columns, rows: rows, range: range)
3937
3094
  entry = { name: name, value: normalized_val, hidden: hidden }
3938
3095
  local_sheet = if scope
3939
3096
  scope == :workbook ? nil : scope.to_s
3940
- elsif sheet || local || ref_sheet
3941
- sheet
3942
3097
  end
3943
3098
  if local_sheet
3944
3099
  # local_sheet_id will be resolved at close time
@@ -3956,24 +3111,20 @@ module Xlsxrb
3956
3111
  @defined_names.map { |dn| dn.is_a?(Elements::DefinedName) ? dn : Elements::DefinedName.new(**dn) }
3957
3112
  end
3958
3113
 
3959
- # Sets or gets the print area for the current or named sheet.
3114
+ # Returns the print area range for the current or named sheet, or nil if none.
3960
3115
  #
3961
- # @param range [String, Object, nil] Cell range (e.g. "A1:G50").
3962
3116
  # @param sheet [String, nil] Target sheet name.
3963
- # @return [String, nil, void]
3117
+ # @return [String, nil]
3964
3118
  # @api public
3965
- #: (?untyped range, ?sheet: String?) -> (String | nil | void)
3966
- def print_area(range = OMITTED, sheet: nil)
3967
- return @current_print_area if range.equal?(OMITTED)
3968
-
3969
- @current_print_area = range
3970
- sheet_name = sheet || @current_sheet || "Sheet1"
3971
- @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sheet_name }
3972
- if range
3973
- value = "'#{sheet_name}'!#{absolute_range(range)}"
3974
- defined_name("_xlnm.Print_Area", value, sheet: sheet_name, scope: sheet_name)
3119
+ #: (?sheet: String?) -> String?
3120
+ def print_area(sheet: nil)
3121
+ sheet_name = sheet || @current_sheet
3122
+ if sheet_name.nil? || sheet_name == @current_sheet
3123
+ @current_print_area
3124
+ else
3125
+ dn = @defined_names.find { |d| d[:name] == "_xlnm.Print_Area" && d[:local_sheet_name] == sheet_name }
3126
+ dn ? dn[:value].split("!", 2).last.tr("$", "") : nil
3975
3127
  end
3976
- nil
3977
3128
  end
3978
3129
 
3979
3130
  # Sets the print area for the current worksheet.
@@ -3983,38 +3134,37 @@ module Xlsxrb
3983
3134
  # @api public
3984
3135
  #: (String? range) -> String?
3985
3136
  def print_area=(range)
3986
- print_area(range)
3987
- range
3137
+ set_print_area(range, sheet: @current_sheet)
3988
3138
  end
3989
3139
 
3990
- # Sets or gets print titles for the current or named sheet.
3140
+ # Sets or gets repeating print titles (rows and/or columns) for pagination.
3141
+ #
3142
+ # When called with no row/column arguments, returns the {Elements::PrintTitles} value object or nil.
3143
+ # When called with row/column arguments, sets repeating print titles and returns nil.
3991
3144
  #
3992
3145
  # @param rows [String, Integer, Range, Object, nil] Repeating row range (e.g. "1:2" or 0-based 0..1).
3993
3146
  # @param columns [String, Integer, Symbol, Range, Object, nil] Repeating column range (e.g. "A:B" or 0..1).
3994
- # @param cols [String, Integer, Symbol, Range, Object, nil] Deprecated alias for columns.
3995
3147
  # @param sheet [String, nil] Target sheet name.
3996
3148
  # @return [Elements::PrintTitles, nil, void]
3997
3149
  # @api public
3998
- #: (?rows: untyped, ?columns: untyped, ?cols: untyped, ?sheet: String?) -> (Elements::PrintTitles | nil | void)
3999
- def print_titles(rows: OMITTED, columns: OMITTED, cols: OMITTED, sheet: nil)
4000
- if rows.equal?(OMITTED) && columns.equal?(OMITTED) && cols.equal?(OMITTED)
4001
- return nil unless @current_print_titles
3150
+ #: () -> Elements::PrintTitles?
3151
+ #: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?, ?sheet: String?) -> void
3152
+ def print_titles(rows: nil, columns: nil, sheet: nil)
3153
+ sheet_name = sheet || @current_sheet || "Sheet1"
3154
+ if rows.nil? && columns.nil?
3155
+ return Elements::PrintTitles.new(rows: @current_print_titles[:rows], columns: @current_print_titles[:columns]) if sheet_name == @current_sheet && @current_print_titles
4002
3156
 
4003
- return Elements::PrintTitles.new(rows: @current_print_titles[:rows], columns: @current_print_titles[:columns] || @current_print_titles[:cols])
4004
- end
3157
+ existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
3158
+ return nil unless existing
4005
3159
 
4006
- warn "[DEPRECATION] `cols:` is deprecated; use `columns:` instead.", uplevel: 1 if cols && !cols.equal?(OMITTED) && columns.equal?(OMITTED)
4007
- r_val = rows.equal?(OMITTED) ? nil : rows
4008
- c_val = if !columns.equal?(OMITTED)
4009
- columns
4010
- elsif !cols.equal?(OMITTED)
4011
- cols
4012
- end
4013
- @current_print_titles = { rows: r_val, columns: c_val }.compact
3160
+ c = Regexp.last_match(1).delete("$") if existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
3161
+ r = Regexp.last_match(1).delete("$") if existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
3162
+ return Elements::PrintTitles.new(rows: r, columns: c)
3163
+ end
4014
3164
 
4015
- c = DslHelpers.normalize_print_titles_columns(c_val)
4016
- r = DslHelpers.normalize_print_titles_rows(r_val)
4017
- sheet_name = sheet || @current_sheet || "Sheet1"
3165
+ @current_print_titles = { rows: rows, columns: columns }.compact if sheet_name == @current_sheet
3166
+ c = DslHelpers.normalize_print_titles_columns(columns)
3167
+ r = DslHelpers.normalize_print_titles_rows(rows)
4018
3168
  existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
4019
3169
  if existing && (r.nil? || c.nil?)
4020
3170
  c = Regexp.last_match(1).delete("$") if c.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
@@ -4106,7 +3256,7 @@ module Xlsxrb
4106
3256
  if opts.empty?
4107
3257
  @workbook_protection ? Elements::WorkbookProtection.new(**@workbook_protection) : nil
4108
3258
  else
4109
- @workbook_protection = opts
3259
+ @workbook_protection = DslHelpers.normalize_workbook_protection(opts)
4110
3260
  nil
4111
3261
  end
4112
3262
  end
@@ -4118,58 +3268,69 @@ module Xlsxrb
4118
3268
  # @api public
4119
3269
  #: (untyped opts) -> void
4120
3270
  def workbook_protection=(opts)
4121
- @workbook_protection = opts.is_a?(Elements::MetadataRecord) ? opts.to_h : opts
3271
+ @workbook_protection = opts.is_a?(Elements::MetadataRecord) ? opts.to_h : (opts && DslHelpers.normalize_workbook_protection(opts))
4122
3272
  end
4123
3273
 
4124
- # @deprecated Use {#workbook_protection} instead.
4125
- #: (**String | Integer | bool | nil opts) -> void
4126
- def protect_workbook(...)
4127
- warn "[DEPRECATION] `protect_workbook` is deprecated; use `workbook_protection` instead.", uplevel: 1
4128
- workbook_protection(...)
4129
- end
4130
-
4131
- # Sets a core document metadata property.
3274
+ # Configures or queries core document properties.
4132
3275
  #
4133
- # @param name [Symbol] Property name.
4134
- # @param value [String, Integer, Time] Property value.
4135
- # @return [void]
4136
- # @api public
4137
- #: (Symbol name, String | Integer | Time value) -> void
4138
- def core_property(name, value)
4139
- @core_properties[name] = value
4140
- end
4141
-
4142
- # Returns core document properties.
3276
+ # When called with no arguments, returns the {Elements::CoreProperties} value object.
3277
+ # When called with keyword options, configures properties and returns nil.
4143
3278
  #
4144
- # @return [Elements::CoreProperties]
3279
+ # @param opts [Hash] Core properties map.
3280
+ # @return [Elements::CoreProperties, void]
4145
3281
  # @api public
4146
3282
  #: () -> Elements::CoreProperties
4147
- def core_properties
4148
- Elements::CoreProperties.new(**@core_properties)
3283
+ #: (**untyped opts) -> void
3284
+ def core_properties(**opts)
3285
+ return Elements::CoreProperties.new(**@core_properties) if opts.empty?
3286
+
3287
+ @core_properties.merge!(opts)
3288
+ nil
4149
3289
  end
4150
3290
 
4151
- # Sets an app document property.
3291
+ # Replaces core document properties.
4152
3292
  #
4153
- # @param name [Symbol] Property name.
4154
- # @param value [String, Integer, Time] Property value.
3293
+ # @param props [Hash, Elements::CoreProperties]
4155
3294
  # @return [void]
4156
3295
  # @api public
4157
- #: (Symbol name, String | Integer | Time value) -> void
4158
- def app_property(name, value)
4159
- # simplecov:disable
4160
- # Edge case / untested delegation block
4161
- norm_name = name.to_sym == :application ? :app_name : name.to_sym
4162
- @app_properties[norm_name] = value
4163
- # simplecov:enable
3296
+ #: (Hash[Symbol, untyped] | Elements::CoreProperties props) -> void
3297
+ def core_properties=(props)
3298
+ h = props.respond_to?(:to_h) ? props.to_h : (props || {})
3299
+ @core_properties = h.transform_keys(&:to_sym)
3300
+ nil
4164
3301
  end
4165
3302
 
4166
- # Returns application document properties.
3303
+ # Configures or queries application document properties.
3304
+ #
3305
+ # When called with no arguments, returns the {Elements::AppProperties} value object.
3306
+ # When called with keyword options, configures properties and returns nil.
4167
3307
  #
4168
- # @return [Elements::AppProperties]
3308
+ # @param opts [Hash] Application properties map.
3309
+ # @return [Elements::AppProperties, void]
4169
3310
  # @api public
4170
3311
  #: () -> Elements::AppProperties
4171
- def app_properties
4172
- Elements::AppProperties.new(**@app_properties)
3312
+ #: (**untyped opts) -> void
3313
+ def app_properties(**opts)
3314
+ return Elements::AppProperties.new(**@app_properties) if opts.empty?
3315
+
3316
+ opts.each do |k, v|
3317
+ norm_name = k.to_sym == :application ? :app_name : k.to_sym
3318
+ @app_properties[norm_name] = v
3319
+ end
3320
+ nil
3321
+ end
3322
+
3323
+ # Replaces application document properties.
3324
+ #
3325
+ # @param props [Hash, Elements::AppProperties]
3326
+ # @return [void]
3327
+ # @api public
3328
+ #: (Hash[Symbol, untyped] | Elements::AppProperties props) -> void
3329
+ def app_properties=(props)
3330
+ h = props.respond_to?(:to_h) ? props.to_h : (props || {})
3331
+ @app_properties = {}
3332
+ app_properties(**h)
3333
+ nil
4173
3334
  end
4174
3335
 
4175
3336
  # Sets multiple core and/or app properties.
@@ -4181,12 +3342,9 @@ module Xlsxrb
4181
3342
  # @api public
4182
3343
  #: (?core: Hash[Symbol, String | Integer | Time]?, ?app: Hash[Symbol, String | Integer | Time]?, ?custom: Hash[String | Symbol, untyped]?) -> void
4183
3344
  def properties(core: nil, app: nil, custom: nil)
4184
- # simplecov:disable
4185
- # Edge case / untested delegation block
4186
- core&.each { |k, v| core_property(k, v) }
4187
- app&.each { |k, v| app_property(k, v) }
3345
+ core_properties(**core) if core
3346
+ app_properties(**app) if app
4188
3347
  custom&.each { |k, v| custom_property(k.to_s, v) }
4189
- # simplecov:enable
4190
3348
  end
4191
3349
 
4192
3350
  # Adds a custom document property.
@@ -4240,7 +3398,7 @@ module Xlsxrb
4240
3398
  resolved_names = resolve_defined_names(@defined_names, @sheets)
4241
3399
 
4242
3400
  @workbook_properties[:active_sheet] = @active_sheet unless @active_sheet.nil?
4243
- @workbook_properties[:active_tab] = @active_sheet unless @active_sheet.nil?
3401
+ @workbook_properties[:active_sheet_index] = @active_sheet unless @active_sheet.nil?
4244
3402
  @workbook_properties[:first_sheet] = @first_sheet unless @first_sheet.nil?
4245
3403
  @workbook_properties[:show_sheet_tabs] = @show_sheet_tabs unless @show_sheet_tabs.nil?
4246
3404
  @workbook_properties[:tab_ratio] = @tab_ratio unless @tab_ratio.nil?
@@ -4289,6 +3447,117 @@ module Xlsxrb
4289
3447
 
4290
3448
  private
4291
3449
 
3450
+ # Raises ArgumentError for any cell style name that has not been defined.
3451
+ #: (untyped cell_styles) -> void
3452
+ def check_style_names!(cell_styles)
3453
+ if cell_styles.is_a?(Array)
3454
+ cell_styles.each { |name| check_style_name!(name) }
3455
+ else
3456
+ check_style_name!(cell_styles)
3457
+ end
3458
+ end
3459
+
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
+
3517
+ styles_for_cells = cell_styles.is_a?(Array) ? cell_styles : nil
3518
+ idx = -1
3519
+ last = values.size - 1
3520
+ while idx < last
3521
+ idx += 1
3522
+ value = values[idx]
3523
+ next unless value.is_a?(Date) || value.is_a?(Time)
3524
+
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?
3527
+ next unless style_name.is_a?(String) || style_name.is_a?(Symbol)
3528
+
3529
+ variant = DslHelpers.date_style_variant(value, style_name.to_s, @styles[style_name.to_s])
3530
+ next unless variant
3531
+
3532
+ variant_name, number_format = variant
3533
+ unless @style_name_to_id.key?(variant_name)
3534
+ variant_builder = @styles[style_name.to_s].with_number_format(variant_name, number_format)
3535
+ @styles[variant_name] = variant_builder
3536
+ @style_name_to_id[variant_name] = variant_builder.register_with(@style_writer)
3537
+ end
3538
+ styles_for_cells ||= Array.new(values.size, cell_styles)
3539
+ styles_for_cells = styles_for_cells.dup if styles_for_cells.equal?(cell_styles)
3540
+ styles_for_cells[idx] = variant_name
3541
+ end
3542
+ styles_for_cells || cell_styles
3543
+ end
3544
+
3545
+ def ensure_sheet_started!
3546
+ sheet if @current_sheet.nil?
3547
+ end
3548
+
3549
+ #: (String? range, ?sheet: String?) -> String?
3550
+ def set_print_area(range, sheet: nil)
3551
+ sheet_name = sheet || @current_sheet || "Sheet1"
3552
+ @current_print_area = range&.to_s if sheet_name == @current_sheet
3553
+ @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sheet_name }
3554
+ if range
3555
+ value = "'#{sheet_name}'!#{absolute_range(range)}"
3556
+ defined_name("_xlnm.Print_Area", value, sheet: sheet_name, scope: sheet_name)
3557
+ end
3558
+ range&.to_s
3559
+ end
3560
+
4292
3561
  #: (untyped range) -> untyped
4293
3562
  def absolute_range(range)
4294
3563
  DslHelpers.absolute_range(range)
@@ -4316,7 +3585,7 @@ module Xlsxrb
4316
3585
  unless @current_conditional_formats.empty?
4317
3586
  @dxfs ||= []
4318
3587
  @current_conditional_formats = @current_conditional_formats.map do |rule|
4319
- next rule if rule.respond_to?(:dxf_id) ? rule.dxf_id : (rule.is_a?(Hash) && (rule[:dxf_id] || rule[:format_id]))
3588
+ next rule if rule[:dxf_id] || rule[:format_id]
4320
3589
 
4321
3590
  normalized = rule.dup
4322
3591
  dxf = normalized.delete(:dxf) || DslHelpers.extract_dxf_from_rule!(normalized)
@@ -4328,7 +3597,6 @@ module Xlsxrb
4328
3597
  dxf_id = @dxfs.size - 1
4329
3598
  end
4330
3599
  normalized[:dxf_id] = dxf_id
4331
- normalized[:format_id] = dxf_id
4332
3600
  normalized
4333
3601
  end
4334
3602
  end
@@ -4366,7 +3634,7 @@ module Xlsxrb
4366
3634
  sheet_format: @current_sheet_format,
4367
3635
  sheet_view: @current_sheet_view,
4368
3636
  row_breaks: @current_row_breaks,
4369
- col_breaks: @current_col_breaks,
3637
+ column_breaks: @current_col_breaks,
4370
3638
  protected_ranges: @current_protected_ranges,
4371
3639
  cell_watches: @current_cell_watches,
4372
3640
  ignored_errors: @current_ignored_errors,
@@ -4377,8 +3645,10 @@ module Xlsxrb
4377
3645
  sheet_data[:cells] = @current_cells if @current_cells && !@current_cells.empty?
4378
3646
  @current_cells = nil
4379
3647
 
4380
- temp_wb_writer = Ooxml::WorkbookWriter.new(sheets: [sheet_data])
4381
- info = temp_wb_writer.prepare_sheet_auxiliary(sheet_data, @current_sheet_index - 1)
3648
+ # One writer for all sheets, so that drawing, comment, table, and pivot part numbers
3649
+ # continue across sheets as write_package_parts numbers the parts.
3650
+ @auxiliary_writer ||= Ooxml::WorkbookWriter.new(sheets: [])
3651
+ info = @auxiliary_writer.prepare_sheet_auxiliary(sheet_data, @current_sheet_index - 1)
4382
3652
 
4383
3653
  @current_row_writer.finish(
4384
3654
  drawing_rid: info[:drawing_rid],
@@ -4397,7 +3667,7 @@ module Xlsxrb
4397
3667
  page_setup: @current_page_setup.empty? ? nil : @current_page_setup,
4398
3668
  header_footer: @current_header_footer.empty? ? nil : @current_header_footer,
4399
3669
  row_breaks: @current_row_breaks.empty? ? nil : @current_row_breaks,
4400
- col_breaks: @current_col_breaks.empty? ? nil : @current_col_breaks,
3670
+ column_breaks: @current_col_breaks.empty? ? nil : @current_col_breaks,
4401
3671
  cell_watches: @current_cell_watches.empty? ? nil : @current_cell_watches,
4402
3672
  ignored_errors: @current_ignored_errors.empty? ? nil : @current_ignored_errors,
4403
3673
  phonetic_pr: @current_phonetic_properties,